org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException Java Examples

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException. 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: 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 #2
Source File: JobResultDeserializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncompleteJobResult() throws Exception {
	try {
		objectMapper.readValue("{\n" +
			"\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\"\n" +
			"}", JobResult.class);
	} catch (final JsonMappingException e) {
		assertThat(e.getMessage(), containsString("Could not deserialize JobResult"));
	}
}
 
Example #3
Source File: JobResultDeserializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidType() throws Exception {
	try {
		objectMapper.readValue("{\n" +
			"\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\",\n" +
			"\t\"net-runtime\": \"invalid\"\n" +
			"}", JobResult.class);
	} catch (final JsonMappingException e) {
		assertThat(e.getMessage(), containsString("Expected token VALUE_NUMBER_INT (was VALUE_STRING)"));
	}
}
 
Example #4
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 #5
Source File: Environment.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an String.
 */
public static Environment parse(String content) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(content, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example #6
Source File: Environment.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an URL.
 */
public static Environment parse(URL url) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(url, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example #7
Source File: JobResultDeserializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncompleteJobResult() throws Exception {
	try {
		objectMapper.readValue("{\n" +
			"\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\"\n" +
			"}", JobResult.class);
	} catch (final JsonMappingException e) {
		assertThat(e.getMessage(), containsString("Could not deserialize JobResult"));
	}
}
 
Example #8
Source File: JobResultDeserializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidType() throws Exception {
	try {
		objectMapper.readValue("{\n" +
			"\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\",\n" +
			"\t\"net-runtime\": \"invalid\"\n" +
			"}", JobResult.class);
	} catch (final JsonMappingException e) {
		assertThat(e.getMessage(), containsString("Expected token VALUE_NUMBER_INT (was VALUE_STRING)"));
	}
}
 
Example #9
Source File: Environment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an URL.
 */
public static Environment parse(URL url) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(url, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example #10
Source File: Environment.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an String.
 */
public static Environment parse(String content) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(content, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example #11
Source File: Environment.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an URL.
 */
public static Environment parse(URL url) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(url, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example #12
Source File: JobResultDeserializerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testIncompleteJobResult() throws Exception {
	try {
		objectMapper.readValue("{\n" +
			"\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\"\n" +
			"}", JobResult.class);
	} catch (final JsonMappingException e) {
		assertThat(e.getMessage(), containsString("Could not deserialize JobResult"));
	}
}
 
Example #13
Source File: JobResultDeserializerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidType() throws Exception {
	try {
		objectMapper.readValue("{\n" +
			"\t\"id\": \"1bb5e8c7df49938733b7c6a73678de6a\",\n" +
			"\t\"net-runtime\": \"invalid\"\n" +
			"}", JobResult.class);
	} catch (final JsonMappingException e) {
		assertThat(e.getMessage(), containsString("Expected token VALUE_NUMBER_INT (was VALUE_STRING)"));
	}
}
 
Example #14
Source File: JobResultDeserializer.java    From Flink-CEPplus 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 #15
Source File: Environment.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an environment file from an String.
 */
public static Environment parse(String content) throws IOException {
	try {
		return new ConfigUtil.LowerCaseYamlMapper().readValue(content, Environment.class);
	} catch (JsonMappingException e) {
		throw new SqlClientException("Could not parse environment file. Cause: " + e.getMessage());
	}
}
 
Example #16
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
	JobID jobId = null;
	ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
	long netRuntime = -1;
	SerializedThrowable serializedThrowable = null;
	Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;

	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}

		final String fieldName = p.getValueAsString();
		switch (fieldName) {
			case JobResultSerializer.FIELD_NAME_JOB_ID:
				assertNextToken(p, JsonToken.VALUE_STRING);
				jobId = jobIdDeserializer.deserialize(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS:
				assertNextToken(p, JsonToken.VALUE_STRING);
				applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase());
				break;
			case JobResultSerializer.FIELD_NAME_NET_RUNTIME:
				assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
				netRuntime = p.getLongValue();
				break;
			case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
				assertNextToken(p, JsonToken.START_OBJECT);
				accumulatorResults = parseAccumulatorResults(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
				assertNextToken(p, JsonToken.START_OBJECT);
				serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
				break;
			default:
				// ignore unknown fields
		}
	}

	try {
		return new JobResult.Builder()
			.jobId(jobId)
			.applicationStatus(applicationStatus)
			.netRuntime(netRuntime)
			.accumulatorResults(accumulatorResults)
			.serializedThrowable(serializedThrowable)
			.build();
	} catch (final RuntimeException e) {
		throw new JsonMappingException(
			null,
			"Could not deserialize " + JobResult.class.getSimpleName(),
			e);
	}
}
 
Example #17
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
	JobID jobId = null;
	ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
	long netRuntime = -1;
	SerializedThrowable serializedThrowable = null;
	Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;

	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}

		final String fieldName = p.getValueAsString();
		switch (fieldName) {
			case JobResultSerializer.FIELD_NAME_JOB_ID:
				assertNextToken(p, JsonToken.VALUE_STRING);
				jobId = jobIdDeserializer.deserialize(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS:
				assertNextToken(p, JsonToken.VALUE_STRING);
				applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase());
				break;
			case JobResultSerializer.FIELD_NAME_NET_RUNTIME:
				assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
				netRuntime = p.getLongValue();
				break;
			case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
				assertNextToken(p, JsonToken.START_OBJECT);
				accumulatorResults = parseAccumulatorResults(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
				assertNextToken(p, JsonToken.START_OBJECT);
				serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
				break;
			default:
				// ignore unknown fields
		}
	}

	try {
		return new JobResult.Builder()
			.jobId(jobId)
			.applicationStatus(applicationStatus)
			.netRuntime(netRuntime)
			.accumulatorResults(accumulatorResults)
			.serializedThrowable(serializedThrowable)
			.build();
	} catch (final RuntimeException e) {
		throw new JsonMappingException(
			null,
			"Could not deserialize " + JobResult.class.getSimpleName(),
			e);
	}
}
 
Example #18
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public JobResult deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException {
	JobID jobId = null;
	ApplicationStatus applicationStatus = ApplicationStatus.UNKNOWN;
	long netRuntime = -1;
	SerializedThrowable serializedThrowable = null;
	Map<String, SerializedValue<OptionalFailure<Object>>> accumulatorResults = null;

	while (true) {
		final JsonToken jsonToken = p.nextToken();
		assertNotEndOfInput(p, jsonToken);
		if (jsonToken == JsonToken.END_OBJECT) {
			break;
		}

		final String fieldName = p.getValueAsString();
		switch (fieldName) {
			case JobResultSerializer.FIELD_NAME_JOB_ID:
				assertNextToken(p, JsonToken.VALUE_STRING);
				jobId = jobIdDeserializer.deserialize(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_APPLICATION_STATUS:
				assertNextToken(p, JsonToken.VALUE_STRING);
				applicationStatus = ApplicationStatus.valueOf(p.getValueAsString().toUpperCase());
				break;
			case JobResultSerializer.FIELD_NAME_NET_RUNTIME:
				assertNextToken(p, JsonToken.VALUE_NUMBER_INT);
				netRuntime = p.getLongValue();
				break;
			case JobResultSerializer.FIELD_NAME_ACCUMULATOR_RESULTS:
				assertNextToken(p, JsonToken.START_OBJECT);
				accumulatorResults = parseAccumulatorResults(p, ctxt);
				break;
			case JobResultSerializer.FIELD_NAME_FAILURE_CAUSE:
				assertNextToken(p, JsonToken.START_OBJECT);
				serializedThrowable = serializedThrowableDeserializer.deserialize(p, ctxt);
				break;
			default:
				// ignore unknown fields
		}
	}

	try {
		return new JobResult.Builder()
			.jobId(jobId)
			.applicationStatus(applicationStatus)
			.netRuntime(netRuntime)
			.accumulatorResults(accumulatorResults)
			.serializedThrowable(serializedThrowable)
			.build();
	} catch (final RuntimeException e) {
		throw new JsonMappingException(
			null,
			"Could not deserialize " + JobResult.class.getSimpleName(),
			e);
	}
}