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

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken. 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: ConfigUtil.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
public LowerCaseYamlMapper() {
	super(new YAMLFactory() {
		@Override
		protected YAMLParser _createParser(InputStream in, IOContext ctxt) throws IOException {
			final Reader r = _createReader(in, null, ctxt);
			// normalize all key to lower case keys
			return new YAMLParser(ctxt, _getBufferRecycler(), _parserFeatures, _yamlParserFeatures, _objectCodec, r) {
				@Override
				public String getCurrentName() throws IOException {
					if (_currToken == JsonToken.FIELD_NAME) {
						return _currentFieldName.toLowerCase();
					}
					return super.getCurrentName();
				}

				@Override
				public String getText() throws IOException {
					if (_currToken == JsonToken.FIELD_NAME) {
						return _currentFieldName.toLowerCase();
					}
					return super.getText();
				}
			};
		}
	});
}
 
Example #2
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 #3
Source File: ConfigUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public LowerCaseYamlMapper() {
	super(new YAMLFactory() {
		@Override
		protected YAMLParser _createParser(InputStream in, IOContext ctxt) throws IOException {
			final Reader r = _createReader(in, null, ctxt);
			// normalize all key to lower case keys
			return new YAMLParser(ctxt, _getBufferRecycler(), _parserFeatures, _yamlParserFeatures, _objectCodec, r) {
				@Override
				public String getCurrentName() throws IOException {
					if (_currToken == JsonToken.FIELD_NAME) {
						return _currentFieldName.toLowerCase();
					}
					return super.getCurrentName();
				}

				@Override
				public String getText() throws IOException {
					if (_currToken == JsonToken.FIELD_NAME) {
						return _currentFieldName.toLowerCase();
					}
					return super.getText();
				}
			};
		}
	});
}
 
Example #4
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 #5
Source File: ConfigUtil.java    From flink with Apache License 2.0 6 votes vote down vote up
public LowerCaseYamlMapper() {
	super(new YAMLFactory() {
		@Override
		protected YAMLParser _createParser(InputStream in, IOContext ctxt) throws IOException {
			final Reader r = _createReader(in, null, ctxt);
			// normalize all key to lower case keys
			return new YAMLParser(ctxt, _getBufferRecycler(), _parserFeatures, _yamlParserFeatures, _objectCodec, r) {
				@Override
				public String getCurrentName() throws IOException {
					if (_currToken == JsonToken.FIELD_NAME) {
						return _currentFieldName.toLowerCase();
					}
					return super.getCurrentName();
				}

				@Override
				public String getText() throws IOException {
					if (_currToken == JsonToken.FIELD_NAME) {
						return _currentFieldName.toLowerCase();
					}
					return super.getText();
				}
			};
		}
	});
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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);
	}
}
 
Example #11
Source File: JobResultDeserializer.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Asserts that the provided JsonToken is not null, i.e., not at the end of the input.
 */
private static void assertNotEndOfInput(
		final JsonParser p,
		@Nullable final JsonToken jsonToken) {
	checkState(jsonToken != null, "Unexpected end of input at %s", p.getCurrentLocation());
}
 
Example #12
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 #13
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Asserts that the provided JsonToken is not null, i.e., not at the end of the input.
 */
private static void assertNotEndOfInput(
		final JsonParser p,
		@Nullable final JsonToken jsonToken) {
	checkState(jsonToken != null, "Unexpected end of input at %s", p.getCurrentLocation());
}
 
Example #14
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 #15
Source File: JobResultDeserializer.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Asserts that the provided JsonToken is not null, i.e., not at the end of the input.
 */
private static void assertNotEndOfInput(
		final JsonParser p,
		@Nullable final JsonToken jsonToken) {
	checkState(jsonToken != null, "Unexpected end of input at %s", p.getCurrentLocation());
}