use of com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.
the class ServletResponseResultWriter method getWriteLongAsStringModule.
private static SimpleModule getWriteLongAsStringModule() {
JsonSerializer<Long> longSerializer = new JsonSerializer<Long>() {
@Override
public void serialize(Long value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeString(value.toString());
}
};
SimpleModule writeLongAsStringModule = new SimpleModule("writeLongAsStringModule", new Version(1, 0, 0, null, null, null));
// long (primitive)
writeLongAsStringModule.addSerializer(Long.TYPE, longSerializer);
// Long (class)
writeLongAsStringModule.addSerializer(Long.class, longSerializer);
return writeLongAsStringModule;
}
use of com.fasterxml.jackson.databind.SerializerProvider in project apache-kafka-on-k8s by banzaicloud.
the class VerifiableConsumer method addKafkaSerializerModule.
private void addKafkaSerializerModule() {
SimpleModule kafka = new SimpleModule();
kafka.addSerializer(TopicPartition.class, new JsonSerializer<TopicPartition>() {
@Override
public void serialize(TopicPartition tp, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeObjectField("topic", tp.topic());
gen.writeObjectField("partition", tp.partition());
gen.writeEndObject();
}
});
mapper.registerModule(kafka);
}
use of com.fasterxml.jackson.databind.SerializerProvider in project GMM by Katharsas.
the class ApplicationConfiguration method customJackson2HttpMessageConverter.
/**
* Configure Jackson (enable Path to Json/String conversion)
*/
@Bean
public MappingJackson2HttpMessageConverter customJackson2HttpMessageConverter(MappingJackson2HttpMessageConverter converter) {
final ObjectMapper objectMapper = new ObjectMapper();
final SimpleModule sm = new SimpleModule();
sm.addSerializer(Path.class, new StdSerializer<Path>(Path.class) {
private static final long serialVersionUID = 8963132152002562810L;
@Override
public void serialize(Path value, JsonGenerator gen, SerializerProvider serializers) throws IOException, JsonProcessingException {
gen.writeString(value.toString());
}
});
objectMapper.registerModule(sm);
converter.setObjectMapper(objectMapper);
return converter;
}
use of com.fasterxml.jackson.databind.SerializerProvider in project kafka by apache.
the class VerifiableConsumer method addKafkaSerializerModule.
private void addKafkaSerializerModule() {
SimpleModule kafka = new SimpleModule();
kafka.addSerializer(TopicPartition.class, new JsonSerializer<TopicPartition>() {
@Override
public void serialize(TopicPartition tp, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeObjectField("topic", tp.topic());
gen.writeObjectField("partition", tp.partition());
gen.writeEndObject();
}
});
mapper.registerModule(kafka);
}
use of com.fasterxml.jackson.databind.SerializerProvider in project dhis2-core by dhis2.
the class CustomLastUpdatedUserSerializerTest method serializeJson.
@Test
void serializeJson() throws Exception {
Writer jsonWriter = new StringWriter();
JsonGenerator jsonGenerator = new JsonFactory().createGenerator(jsonWriter);
SerializerProvider serializerProvider = new ObjectMapper().getSerializerProvider();
new CustomLastUpdatedUserSerializer().serialize(user, jsonGenerator, serializerProvider);
jsonGenerator.flush();
assertEquals("{\"id\":\"jshfdkd323\",\"name\":\"Peter Brown\"}", jsonWriter.toString());
}
Aggregations