org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser Java Examples

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestClient.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <P extends ResponseBody> CompletableFuture<P> parseResponse(JsonResponse rawResponse, JavaType responseType) {
	CompletableFuture<P> responseFuture = new CompletableFuture<>();
	final JsonParser jsonParser = objectMapper.treeAsTokens(rawResponse.json);
	try {
		P response = objectMapper.readValue(jsonParser, responseType);
		responseFuture.complete(response);
	} catch (IOException originalException) {
		// the received response did not matched the expected response type

		// lets see if it is an ErrorResponse instead
		try {
			ErrorResponseBody error = objectMapper.treeToValue(rawResponse.getJson(), ErrorResponseBody.class);
			responseFuture.completeExceptionally(new RestClientException(error.errors.toString(), rawResponse.getHttpResponseStatus()));
		} catch (JsonProcessingException jpe2) {
			// if this fails it is either the expected type or response type was wrong, most likely caused
			// by a client/search MessageHeaders mismatch
			LOG.error("Received response was neither of the expected type ({}) nor an error. Response={}", responseType, rawResponse, jpe2);
			responseFuture.completeExceptionally(
				new RestClientException(
					"Response was neither of the expected type(" + responseType + ") nor an error.",
					originalException,
					rawResponse.getHttpResponseStatus()));
		}
	}
	return responseFuture;
}
 
Example #2
Source File: JobConfigInfo.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public JobConfigInfo deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {
	JsonNode rootNode = jsonParser.readValueAsTree();

	final JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).asText());
	final String jobName = rootNode.get(FIELD_NAME_JOB_NAME).asText();

	final ExecutionConfigInfo executionConfigInfo;

	if (rootNode.has(FIELD_NAME_EXECUTION_CONFIG)) {
		executionConfigInfo = RestMapperUtils.getStrictObjectMapper().treeToValue(rootNode.get(FIELD_NAME_EXECUTION_CONFIG), ExecutionConfigInfo.class);
	} else {
		executionConfigInfo = null;
	}

	return new JobConfigInfo(jobId, jobName, executionConfigInfo);
}
 
Example #3
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, SerializedValue<OptionalFailure<Object>>> parseAccumulatorResults(
		final JsonParser p,
		final DeserializationContext ctxt) throws IOException {

	final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = new HashMap<>();
	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}
		final String accumulatorName = p.getValueAsString();
		p.nextValue();
		accumulatorResults.put(
			accumulatorName,
			(SerializedValue<OptionalFailure<Object>>) serializedValueDeserializer.deserialize(p, ctxt));
	}
	return accumulatorResults;
}
 
Example #4
Source File: JsonRowSchemaConverter.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a JSON schema into Flink's type information. Throws an exception if the schema
 * cannot converted because of loss of precision or too flexible schema.
 *
 * <p>The converter can resolve simple schema references to solve those cases where entities
 * are defined at the beginning and then used throughout a document.
 */
@SuppressWarnings("unchecked")
public static <T> TypeInformation<T> convert(String jsonSchema) {
	Preconditions.checkNotNull(jsonSchema, "JSON schema");
	final ObjectMapper mapper = new ObjectMapper();
	mapper.getFactory()
		.enable(JsonParser.Feature.ALLOW_COMMENTS)
		.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
		.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
	final JsonNode node;
	try {
		node = mapper.readTree(jsonSchema);
	} catch (IOException e) {
		throw new IllegalArgumentException(
			"Invalid JSON schema.", e);
	}
	return (TypeInformation<T>) convertType("<root>", node, node);
}
 
Example #5
Source File: RestClient.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static <P extends ResponseBody> CompletableFuture<P> parseResponse(JsonResponse rawResponse, JavaType responseType) {
	CompletableFuture<P> responseFuture = new CompletableFuture<>();
	final JsonParser jsonParser = objectMapper.treeAsTokens(rawResponse.json);
	try {
		P response = objectMapper.readValue(jsonParser, responseType);
		responseFuture.complete(response);
	} catch (IOException originalException) {
		// the received response did not matched the expected response type

		// lets see if it is an ErrorResponse instead
		try {
			ErrorResponseBody error = objectMapper.treeToValue(rawResponse.getJson(), ErrorResponseBody.class);
			responseFuture.completeExceptionally(new RestClientException(error.errors.toString(), rawResponse.getHttpResponseStatus()));
		} catch (JsonProcessingException jpe2) {
			// if this fails it is either the expected type or response type was wrong, most likely caused
			// by a client/search MessageHeaders mismatch
			LOG.error("Received response was neither of the expected type ({}) nor an error. Response={}", responseType, rawResponse, jpe2);
			responseFuture.completeExceptionally(
				new RestClientException(
					"Response was neither of the expected type(" + responseType + ") nor an error.",
					originalException,
					rawResponse.getHttpResponseStatus()));
		}
	}
	return responseFuture;
}
 
Example #6
Source File: JsonRowSchemaConverter.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a JSON schema into Flink's type information. Throws an exception if the schema
 * cannot converted because of loss of precision or too flexible schema.
 *
 * <p>The converter can resolve simple schema references to solve those cases where entities
 * are defined at the beginning and then used throughout a document.
 */
@SuppressWarnings("unchecked")
public static <T> TypeInformation<T> convert(String jsonSchema) {
	Preconditions.checkNotNull(jsonSchema, "JSON schema");
	final ObjectMapper mapper = new ObjectMapper();
	mapper.getFactory()
		.enable(JsonParser.Feature.ALLOW_COMMENTS)
		.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
		.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
	final JsonNode node;
	try {
		node = mapper.readTree(jsonSchema);
	} catch (IOException e) {
		throw new IllegalArgumentException(
			"Invalid JSON schema.", e);
	}
	return (TypeInformation<T>) convertType("<root>", node, node);
}
 
Example #7
Source File: JsonJobGraphGenerationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecutionResult execute(String jobName) throws Exception {
	Plan plan = createProgramPlan(jobName);

	Optimizer pc = new Optimizer(new Configuration());
	OptimizedPlan op = pc.compile(plan);

	JobGraphGenerator jgg = new JobGraphGenerator();
	JobGraph jobGraph = jgg.compileJobGraph(op);

	String jsonPlan = JsonPlanGenerator.generatePlan(jobGraph);

	// first check that the JSON is valid
	JsonParser parser = new JsonFactory().createJsonParser(jsonPlan);
	while (parser.nextToken() != null) {}

	validator.validateJson(jsonPlan);

	throw new AbortError();
}
 
Example #8
Source File: JobConfigInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public JobConfigInfo deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {
	JsonNode rootNode = jsonParser.readValueAsTree();

	final JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).asText());
	final String jobName = rootNode.get(FIELD_NAME_JOB_NAME).asText();

	final ExecutionConfigInfo executionConfigInfo;

	if (rootNode.has(FIELD_NAME_EXECUTION_CONFIG)) {
		executionConfigInfo = RestMapperUtils.getStrictObjectMapper().treeToValue(rootNode.get(FIELD_NAME_EXECUTION_CONFIG), ExecutionConfigInfo.class);
	} else {
		executionConfigInfo = null;
	}

	return new JobConfigInfo(jobId, jobName, executionConfigInfo);
}
 
Example #9
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, SerializedValue<OptionalFailure<Object>>> parseAccumulatorResults(
		final JsonParser p,
		final DeserializationContext ctxt) throws IOException {

	final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = new HashMap<>();
	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}
		final String accumulatorName = p.getValueAsString();
		p.nextValue();
		accumulatorResults.put(
			accumulatorName,
			(SerializedValue<OptionalFailure<Object>>) serializedValueDeserializer.deserialize(p, ctxt));
	}
	return accumulatorResults;
}
 
Example #10
Source File: JsonRowSchemaConverter.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Converts a JSON schema into Flink's type information. Throws an exception if the schema
 * cannot converted because of loss of precision or too flexible schema.
 *
 * <p>The converter can resolve simple schema references to solve those cases where entities
 * are defined at the beginning and then used throughout a document.
 */
@SuppressWarnings("unchecked")
public static <T> TypeInformation<T> convert(String jsonSchema) {
	Preconditions.checkNotNull(jsonSchema, "JSON schema");
	final ObjectMapper mapper = new ObjectMapper();
	mapper.getFactory()
		.enable(JsonParser.Feature.ALLOW_COMMENTS)
		.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES)
		.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
	final JsonNode node;
	try {
		node = mapper.readTree(jsonSchema);
	} catch (IOException e) {
		throw new IllegalArgumentException(
			"Invalid JSON schema.", e);
	}
	return (TypeInformation<T>) convertType("<root>", node, node);
}
 
Example #11
Source File: PreviewPlanDumpTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private static void verifyPlanDump(Class<?> entrypoint, String... args) throws Exception {
	final PackagedProgram program = PackagedProgram
		.newBuilder()
		.setEntryPointClassName(entrypoint.getName())
		.setArguments(args)
		.build();

	final Pipeline pipeline = PackagedProgramUtils.getPipelineFromProgram(program, new Configuration(), 1, true);

	assertTrue(pipeline instanceof Plan);

	final Plan plan = (Plan) pipeline;

	final List<DataSinkNode> sinks = Optimizer.createPreOptimizedPlan(plan);
	final PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
	final String json = dumper.getPactPlanAsJSON(sinks);

	try (JsonParser parser = new JsonFactory().createParser(json)) {
		while (parser.nextToken() != null) {
		}
	}
}
 
Example #12
Source File: JsonJobGraphGenerationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecutionResult execute(String jobName) throws Exception {
	Plan plan = createProgramPlan(jobName);

	Optimizer pc = new Optimizer(new Configuration());
	OptimizedPlan op = pc.compile(plan);

	JobGraphGenerator jgg = new JobGraphGenerator();
	JobGraph jobGraph = jgg.compileJobGraph(op);

	String jsonPlan = JsonPlanGenerator.generatePlan(jobGraph);

	// first check that the JSON is valid
	JsonParser parser = new JsonFactory().createJsonParser(jsonPlan);
	while (parser.nextToken() != null) {}

	validator.validateJson(jsonPlan);

	throw new AbortError();
}
 
Example #13
Source File: DumpCompiledPlanTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private void verifyOptimizedPlan(Class<?> entrypoint, String... args) throws Exception {
	final PackagedProgram program = PackagedProgram
		.newBuilder()
		.setEntryPointClassName(entrypoint.getName())
		.setArguments(args)
		.build();

	final Pipeline pipeline = PackagedProgramUtils.getPipelineFromProgram(program, new Configuration(), 1, true);

	assertTrue(pipeline instanceof Plan);

	final Plan plan = (Plan) pipeline;

	final OptimizedPlan op = compileNoStats(plan);
	final PlanJSONDumpGenerator dumper = new PlanJSONDumpGenerator();
	final String json = dumper.getOptimizerPlanAsJSON(op);
	try (JsonParser parser = new JsonFactory().createParser(json)) {
		while (parser.nextToken() != null) {
		}
	}
}
 
Example #14
Source File: RestClient.java    From flink with Apache License 2.0 6 votes vote down vote up
private static <P extends ResponseBody> CompletableFuture<P> parseResponse(JsonResponse rawResponse, JavaType responseType) {
	CompletableFuture<P> responseFuture = new CompletableFuture<>();
	final JsonParser jsonParser = objectMapper.treeAsTokens(rawResponse.json);
	try {
		P response = objectMapper.readValue(jsonParser, responseType);
		responseFuture.complete(response);
	} catch (IOException originalException) {
		// the received response did not matched the expected response type

		// lets see if it is an ErrorResponse instead
		try {
			ErrorResponseBody error = objectMapper.treeToValue(rawResponse.getJson(), ErrorResponseBody.class);
			responseFuture.completeExceptionally(new RestClientException(error.errors.toString(), rawResponse.getHttpResponseStatus()));
		} catch (JsonProcessingException jpe2) {
			// if this fails it is either the expected type or response type was wrong, most likely caused
			// by a client/search MessageHeaders mismatch
			LOG.error("Received response was neither of the expected type ({}) nor an error. Response={}", responseType, rawResponse, jpe2);
			responseFuture.completeExceptionally(
				new RestClientException(
					"Response was neither of the expected type(" + responseType + ") nor an error.",
					originalException,
					rawResponse.getHttpResponseStatus()));
		}
	}
	return responseFuture;
}
 
Example #15
Source File: JobConfigInfo.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public JobConfigInfo deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {
	JsonNode rootNode = jsonParser.readValueAsTree();

	final JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).asText());
	final String jobName = rootNode.get(FIELD_NAME_JOB_NAME).asText();

	final ExecutionConfigInfo executionConfigInfo;

	if (rootNode.has(FIELD_NAME_EXECUTION_CONFIG)) {
		executionConfigInfo = RestMapperUtils.getStrictObjectMapper().treeToValue(rootNode.get(FIELD_NAME_EXECUTION_CONFIG), ExecutionConfigInfo.class);
	} else {
		executionConfigInfo = null;
	}

	return new JobConfigInfo(jobId, jobName, executionConfigInfo);
}
 
Example #16
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, SerializedValue<OptionalFailure<Object>>> parseAccumulatorResults(
		final JsonParser p,
		final DeserializationContext ctxt) throws IOException {

	final Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = new HashMap<>();
	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}
		final String accumulatorName = p.getValueAsString();
		p.nextValue();
		accumulatorResults.put(
			accumulatorName,
			(SerializedValue<OptionalFailure<Object>>) serializedValueDeserializer.deserialize(p, ctxt));
	}
	return accumulatorResults;
}
 
Example #17
Source File: JsonJobGraphGenerationTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecutionResult execute(String jobName) throws Exception {
	Plan plan = createProgramPlan(jobName);

	Optimizer pc = new Optimizer(new Configuration());
	OptimizedPlan op = pc.compile(plan);

	JobGraphGenerator jgg = new JobGraphGenerator();
	JobGraph jobGraph = jgg.compileJobGraph(op);

	String jsonPlan = JsonPlanGenerator.generatePlan(jobGraph);

	// first check that the JSON is valid
	JsonParser parser = new JsonFactory().createJsonParser(jsonPlan);
	while (parser.nextToken() != null) {}

	validator.validateJson(jsonPlan);

	throw new AbortError();
}
 
Example #18
Source File: JobPlanInfo.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public RawJson deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {
	final JsonNode rootNode = jsonParser.readValueAsTree();
	return new RawJson(rootNode.toString());
}
 
Example #19
Source File: MetricCollectionResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public MetricCollectionResponseBody deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {

	return new MetricCollectionResponseBody(jsonParser.readValueAs(
		new TypeReference<List<Metric>>() {
		}));
}
 
Example #20
Source File: JobPlanInfo.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public RawJson deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {
	final JsonNode rootNode = jsonParser.readValueAsTree();
	return new RawJson(rootNode.toString());
}
 
Example #21
Source File: JobDetails.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public JobDetails deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {

	JsonNode rootNode = jsonParser.readValueAsTree();

	JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).textValue());
	String jobName = rootNode.get(FIELD_NAME_JOB_NAME).textValue();
	long startTime = rootNode.get(FIELD_NAME_START_TIME).longValue();
	long endTime = rootNode.get(FIELD_NAME_END_TIME).longValue();
	long duration = rootNode.get(FIELD_NAME_DURATION).longValue();
	JobStatus jobStatus = JobStatus.valueOf(rootNode.get(FIELD_NAME_STATUS).textValue());
	long lastUpdateTime = rootNode.get(FIELD_NAME_LAST_MODIFICATION).longValue();

	JsonNode tasksNode = rootNode.get("tasks");
	int numTasks = tasksNode.get(FIELD_NAME_TOTAL_NUMBER_TASKS).intValue();

	int[] numVerticesPerExecutionState = new int[ExecutionState.values().length];

	for (ExecutionState executionState : ExecutionState.values()) {
		numVerticesPerExecutionState[executionState.ordinal()] = tasksNode.get(executionState.name().toLowerCase()).intValue();
	}

	return new JobDetails(
		jobId,
		jobName,
		startTime,
		endTime,
		duration,
		jobStatus,
		lastUpdateTime,
		numVerticesPerExecutionState,
		numTasks);
}
 
Example #22
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the token and asserts that it matches the required {@link JsonToken}.
 */
private static void assertNextToken(
		final JsonParser p,
		final JsonToken requiredJsonToken) throws IOException {
	final JsonToken jsonToken = p.nextToken();
	if (jsonToken != requiredJsonToken) {
		throw new JsonMappingException(p, String.format("Expected token %s (was %s)", requiredJsonToken, jsonToken));
	}
}
 
Example #23
Source File: SerializedThrowableDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public SerializedThrowable deserialize(
		final JsonParser p,
		final DeserializationContext ctxt) throws IOException {
	final JsonNode root = p.readValueAsTree();

	final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue();
	try {
		return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader());
	} catch (ClassNotFoundException e) {
		throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e);
	}
}
 
Example #24
Source File: AggregatedMetricsResponseBody.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatedMetricsResponseBody deserialize(
	JsonParser jsonParser,
	DeserializationContext deserializationContext) throws IOException {

	return new AggregatedMetricsResponseBody(jsonParser.readValueAs(
		new TypeReference<List<AggregatedMetric>>() {
		}));
}
 
Example #25
Source File: JobDetails.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public JobDetails deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {

	JsonNode rootNode = jsonParser.readValueAsTree();

	JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).textValue());
	String jobName = rootNode.get(FIELD_NAME_JOB_NAME).textValue();
	long startTime = rootNode.get(FIELD_NAME_START_TIME).longValue();
	long endTime = rootNode.get(FIELD_NAME_END_TIME).longValue();
	long duration = rootNode.get(FIELD_NAME_DURATION).longValue();
	JobStatus jobStatus = JobStatus.valueOf(rootNode.get(FIELD_NAME_STATUS).textValue());
	long lastUpdateTime = rootNode.get(FIELD_NAME_LAST_MODIFICATION).longValue();

	JsonNode tasksNode = rootNode.get("tasks");
	int numTasks = tasksNode.get(FIELD_NAME_TOTAL_NUMBER_TASKS).intValue();

	int[] numVerticesPerExecutionState = new int[ExecutionState.values().length];

	for (ExecutionState executionState : ExecutionState.values()) {
		numVerticesPerExecutionState[executionState.ordinal()] = tasksNode.get(executionState.name().toLowerCase()).intValue();
	}

	return new JobDetails(
		jobId,
		jobName,
		startTime,
		endTime,
		duration,
		jobStatus,
		lastUpdateTime,
		numVerticesPerExecutionState,
		numTasks);
}
 
Example #26
Source File: MetricCollectionResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public MetricCollectionResponseBody deserialize(
		JsonParser jsonParser,
		DeserializationContext deserializationContext) throws IOException {

	return new MetricCollectionResponseBody(jsonParser.readValueAs(
		new TypeReference<List<Metric>>() {
		}));
}
 
Example #27
Source File: AggregatedMetricsResponseBody.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatedMetricsResponseBody deserialize(
	JsonParser jsonParser,
	DeserializationContext deserializationContext) throws IOException {

	return new AggregatedMetricsResponseBody(jsonParser.readValueAs(
		new TypeReference<List<AggregatedMetric>>() {
		}));
}
 
Example #28
Source File: SerializedThrowableDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public SerializedThrowable deserialize(
		final JsonParser p,
		final DeserializationContext ctxt) throws IOException {
	final JsonNode root = p.readValueAsTree();

	final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue();
	try {
		return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader());
	} catch (ClassNotFoundException e) {
		throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e);
	}
}
 
Example #29
Source File: SerializedThrowableDeserializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public SerializedThrowable deserialize(
		final JsonParser p,
		final DeserializationContext ctxt) throws IOException {
	final JsonNode root = p.readValueAsTree();

	final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue();
	try {
		return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader());
	} catch (ClassNotFoundException e) {
		throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e);
	}
}
 
Example #30
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Advances the token and asserts that it matches the required {@link JsonToken}.
 */
private static void assertNextToken(
		final JsonParser p,
		final JsonToken requiredJsonToken) throws IOException {
	final JsonToken jsonToken = p.nextToken();
	if (jsonToken != requiredJsonToken) {
		throw new JsonMappingException(p, String.format("Expected token %s (was %s)", requiredJsonToken, jsonToken));
	}
}