use of org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer 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.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer 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);
}
});
};
}
Aggregations