use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project rpki-validator-3 by RIPE-NCC.
the class ApiConfig method customizeLinksRendering.
@Bean
public Jackson2ObjectMapperBuilderCustomizer customizeLinksRendering() {
return (jacksonObjectMapperBuilder) -> {
jacksonObjectMapperBuilder.serializerByType(Links.class, new JsonObjectSerializer<Links>() {
@Override
protected void serializeObject(Links value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
for (Link link : value) {
jgen.writeStringField(link.getRel(), link.getHref());
}
}
});
jacksonObjectMapperBuilder.deserializerByType(Links.class, new JsonObjectDeserializer<Links>() {
@Override
protected Links deserializeObject(JsonParser jsonParser, DeserializationContext context, ObjectCodec codec, JsonNode tree) throws IOException {
Iterator<Map.Entry<String, JsonNode>> iterator = tree.fields();
List<Link> links = new ArrayList<>();
while (iterator.hasNext()) {
Map.Entry<String, JsonNode> field = iterator.next();
links.add(new Link(field.getValue().asText(), field.getKey()));
}
return new Links(links);
}
});
};
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project eureka by Netflix.
the class DeserializerStringCacheTest method testUppercaseConversionWithLowercasePreset.
@Test
public void testUppercaseConversionWithLowercasePreset() throws IOException {
DeserializationContext deserializationContext = mock(DeserializationContext.class);
DeserializerStringCache deserializerStringCache = DeserializerStringCache.from(deserializationContext);
String lowerCaseValue = deserializerStringCache.apply("value", CacheScope.APPLICATION_SCOPE);
assertThat(lowerCaseValue, is("value"));
JsonParser jsonParser = mock(JsonParser.class);
when(jsonParser.getTextCharacters()).thenReturn(new char[] { 'v', 'a', 'l', 'u', 'e' });
when(jsonParser.getTextLength()).thenReturn(5);
String upperCaseValue = deserializerStringCache.apply(jsonParser, CacheScope.APPLICATION_SCOPE, () -> "VALUE");
assertThat(upperCaseValue, is("VALUE"));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project eureka by Netflix.
the class DeserializerStringCacheTest method testUppercaseConversionWithLongString.
@Test
public void testUppercaseConversionWithLongString() throws IOException {
DeserializationContext deserializationContext = mock(DeserializationContext.class);
DeserializerStringCache deserializerStringCache = DeserializerStringCache.from(deserializationContext);
char[] lowercaseValue = new char[1024];
Arrays.fill(lowercaseValue, 'a');
JsonParser jsonParser = mock(JsonParser.class);
when(jsonParser.getText()).thenReturn(new String(lowercaseValue));
when(jsonParser.getTextCharacters()).thenReturn(lowercaseValue);
when(jsonParser.getTextOffset()).thenReturn(0);
when(jsonParser.getTextLength()).thenReturn(lowercaseValue.length);
String upperCaseValue = deserializerStringCache.apply(jsonParser, CacheScope.APPLICATION_SCOPE, () -> {
try {
return jsonParser.getText().toUpperCase();
} catch (IOException ioe) {
// not likely from mock above
throw new IllegalStateException("mock threw unexpected exception", ioe);
}
});
char[] expectedValueChars = new char[1024];
Arrays.fill(expectedValueChars, 'A');
String expectedValue = new String(expectedValueChars);
assertThat(upperCaseValue, is(expectedValue));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.
the class SerializedThrowableDeserializer method deserialize.
@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);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project flink by apache.
the class JobResultDeserializer method parseAccumulatorResults.
@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;
}
Aggregations