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 incubator-servicecomb-java-chassis by apache.
the class TestAbstractDeserializer method testDeserialize.
@SuppressWarnings("unchecked")
@Test
public void testDeserialize() {
boolean status = false;
try {
DeserializationContext ctxt = Mockito.mock(DeserializationContext.class);
@SuppressWarnings("rawtypes") JsonDeserializer JsonDeserializer = Mockito.mock(JsonDeserializer.class);
Object object = null;
Mockito.when(jsonParser.nextFieldName()).thenReturn("abc", (String) null);
Mockito.when(readerHelpData.getDeser()).thenReturn(JsonDeserializer);
Mockito.when(JsonDeserializer.deserialize(jsonParser, ctxt)).thenReturn(object);
Object deserializeObject = abstractDeserializer.deserialize(jsonParser, ctxt);
Assert.assertNotNull(deserializeObject);
} catch (Exception e) {
status = true;
}
Assert.assertFalse(status);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project jocean-http by isdom.
the class MessageUtil method unserializeAsXml.
public static <T> T unserializeAsXml(final InputStream is, final Class<T> type) {
final XmlMapper mapper = new XmlMapper();
mapper.addHandler(new DeserializationProblemHandler() {
@Override
public boolean handleUnknownProperty(final DeserializationContext ctxt, final JsonParser p, final JsonDeserializer<?> deserializer, final Object beanOrClass, final String propertyName) throws IOException {
LOG.warn("UnknownProperty [{}], just skip", propertyName);
p.skipChildren();
return true;
}
});
try {
return mapper.readValue(is, type);
} catch (Exception e) {
LOG.warn("exception when parse as xml, detail: {}", ExceptionUtils.exception2detail(e));
return null;
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project snow-owl by b2ihealthcare.
the class ExpansionParameterDeserializer method deserialize.
@Override
public Parameter<?> deserialize(JsonParser parser, DeserializationContext arg1) throws IOException, JsonProcessingException {
TreeNode node = parser.readValueAsTree();
ObjectCodec objectCodec = parser.getCodec();
Iterator<String> fieldNames = node.fieldNames();
FhirDataType[] parameterTypes = FhirDataType.values();
FhirDataType parameterType = null;
while (fieldNames.hasNext()) {
String fieldName = (String) fieldNames.next();
if (fieldName.startsWith(VALUE_PREFIX)) {
parameterType = Sets.newHashSet(parameterTypes).stream().filter(t -> t.getSerializedName().equalsIgnoreCase(fieldName)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown expansion parameter type '" + fieldName + "'."));
break;
}
}
if (parameterType == null) {
throw new IllegalArgumentException("Invalid parameter type with null value.");
}
switch(parameterType) {
case URI:
return objectCodec.treeToValue(node, UriParameter.class);
case CODE:
return objectCodec.treeToValue(node, CodeParameter.class);
case DATETIME:
return objectCodec.treeToValue(node, DateTimeParameter.class);
case STRING:
return objectCodec.treeToValue(node, StringParameter.class);
case BOOLEAN:
return objectCodec.treeToValue(node, BooleanParameter.class);
case DECIMAL:
return objectCodec.treeToValue(node, DecimalParameter.class);
case INTEGER:
return objectCodec.treeToValue(node, IntegerParameter.class);
default:
throw new IllegalArgumentException("Unsupported property type '" + parameterType + "'.");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext in project presto by prestodb.
the class TestLocalProperties method testJsonSerialization.
@Test
public void testJsonSerialization() throws Exception {
ObjectMapper mapper = new JsonObjectMapperProvider().get().registerModule(new SimpleModule().addDeserializer(ColumnHandle.class, new JsonDeserializer<ColumnHandle>() {
@Override
public ColumnHandle deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
return new JsonObjectMapperProvider().get().readValue(jsonParser, TestingColumnHandle.class);
}
}));
TestingColumnHandle columnHandle = new TestingColumnHandle("a");
LocalProperty<ColumnHandle> property1 = new ConstantProperty<>(columnHandle);
assertEquals(property1, mapper.readValue(mapper.writeValueAsString(property1), new TypeReference<LocalProperty<ColumnHandle>>() {
}));
LocalProperty<ColumnHandle> property2 = new SortingProperty<>(columnHandle, SortOrder.ASC_NULLS_FIRST);
assertEquals(property2, mapper.readValue(mapper.writeValueAsString(property2), new TypeReference<LocalProperty<ColumnHandle>>() {
}));
LocalProperty<ColumnHandle> property3 = new GroupingProperty<>(ImmutableList.of(columnHandle));
assertEquals(property3, mapper.readValue(mapper.writeValueAsString(property3), new TypeReference<LocalProperty<ColumnHandle>>() {
}));
}
Aggregations