use of com.fasterxml.jackson.databind.SerializerProvider in project api-core by ca-cwds.
the class CmsSystemCodeSerializerTest method serialize_Args$Short$JsonGenerator$SerializerProvider.
@Test
public void serialize_Args$Short$JsonGenerator$SerializerProvider() throws Exception {
SystemCodeCache cache = null;
CmsSystemCodeSerializer target = new CmsSystemCodeSerializer(cache);
// given
Short s = null;
JsonGenerator jgen = mock(JsonGenerator.class);
SerializerProvider sp = mock(SerializerProvider.class);
// e.g. : given(mocked.called()).willReturn(1);
// when
target.serialize(s, jgen, sp);
// then
// e.g. : verify(mocked).called();
}
use of com.fasterxml.jackson.databind.SerializerProvider 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 com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriter method getWriteBlobAsBase64Module.
private static SimpleModule getWriteBlobAsBase64Module() {
JsonSerializer<Blob> dateSerializer = new JsonSerializer<Blob>() {
@Override
public void serialize(Blob value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
byte[] bytes = value.getBytes();
jgen.writeBinary(bytes, 0, bytes.length);
}
};
SimpleModule writeBlobAsBase64Module = new SimpleModule("writeBlobAsBase64Module", new Version(1, 0, 0, null, null, null));
writeBlobAsBase64Module.addSerializer(Blob.class, dateSerializer);
return writeBlobAsBase64Module;
}
use of com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriter method getWriteDateAsStringModule.
private static SimpleModule getWriteDateAsStringModule() {
JsonSerializer<Date> dateSerializer = new JsonSerializer<Date>() {
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(new com.google.api.client.util.DateTime(value).toStringRfc3339());
}
};
SimpleModule writeDateAsStringModule = new SimpleModule("writeDateAsStringModule", new Version(1, 0, 0, null, null, null));
writeDateAsStringModule.addSerializer(Date.class, dateSerializer);
return writeDateAsStringModule;
}
use of com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriter method getWriteSimpleDateAsStringModule.
private static SimpleModule getWriteSimpleDateAsStringModule() {
JsonSerializer<SimpleDate> simpleDateSerializer = new JsonSerializer<SimpleDate>() {
@Override
public void serialize(SimpleDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(String.format("%04d-%02d-%02d", value.getYear(), value.getMonth(), value.getDay()));
}
};
SimpleModule writeSimpleDateAsModule = new SimpleModule("writeSimpleDateAsModule", new Version(1, 0, 0, null, null, null));
writeSimpleDateAsModule.addSerializer(SimpleDate.class, simpleDateSerializer);
return writeSimpleDateAsModule;
}
Aggregations