use of org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project openremote by openremote.
the class EnumWithInterfacesExtension method emitElements.
@SuppressWarnings("rawtypes")
@Override
public void emitElements(Writer writer, Settings settings, boolean exportKeyword, TsModel model) {
if (matchedEnums.isEmpty()) {
return;
}
ObjectMapper objectMapper = new ObjectMapper().registerModule(new SimpleModule().addSerializer(Enum.class, new JsonSerializer<Enum>() {
@Override
public void serialize(Enum anEnum, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeRawValue(anEnum.getClass().getSimpleName() + "." + anEnum.name());
}
})).setAnnotationIntrospector(// Ignore Shape Object so we get proper enum references
ignoreJsonFormatIntrospector);
if (!supportsNullValuesPredicate.test(settings)) {
// Don't output nulls if settings don't support it
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
// Do a topological sort of matched enums to ensure they are output in the correct order
sortEnums(matchedEnums);
for (TsEnumModel tsEnum : matchedEnums) {
final EnumInterfaceModel enumInterfaceModel = parseEnum(tsEnum, model, settings);
// TODO: TsEnumModel should have interface details like TsBeanModel
String implementsStr = Arrays.stream(tsEnum.getOrigin().getInterfaces()).map(i -> {
TsBeanModel beanModel = model.getBean(i);
return beanModel != null ? beanModel.getName().getFullName() : i.getSimpleName();
}).collect(Collectors.joining(" | "));
String fieldsStr = enumInterfaceModel.getFieldTypeMap().entrySet().stream().map(es -> es.getKey() + ": " + es.getValue()).collect(Collectors.joining(TMPL_ENUM_FIELD_SEPARATOR));
if (!fieldsStr.isEmpty()) {
fieldsStr = TMPL_ENUM_FIELD_SEPARATOR + fieldsStr;
}
final Map<String, String> replacements = new LinkedHashMap<>();
replacements.put("\"", settings.quotes);
replacements.put("/*export*/ ", exportKeyword ? "export " : "");
replacements.put(TMPL_ENUM_NAME, tsEnum.getName().getSimpleName());
replacements.put(TMPL_ENUM_IMPLEMENTS, implementsStr);
replacements.put(TMPL_ENUM_FIELDS, fieldsStr);
Emitter.writeTemplate(writer, settings, ENUM_CLASS_HEADER_TEMPLATE, replacements);
enumInterfaceModel.getMemberModels().forEach(enumInterfaceMemberModel -> {
String memberFieldValues = enumInterfaceMemberModel.getMemberFieldValues().entrySet().stream().map(es -> getMemberValue(tsEnum.getName().getFullName(), es.getKey(), es.getValue(), settings, objectMapper)).collect(Collectors.joining(TMPL_ENUM_MEMBER_VALUE_SEPARATOR));
if (!memberFieldValues.isEmpty()) {
memberFieldValues = TMPL_ENUM_MEMBER_VALUE_SEPARATOR + memberFieldValues;
}
replacements.put(TMPL_ENUM_MEMBER_NAME, enumInterfaceMemberModel.getMemberName());
replacements.put(TMPL_ENUM_MEMBER_FIELD_VALUES, memberFieldValues);
Emitter.writeTemplate(writer, settings, ENUM_CLASS_MEMBER_TEMPLATE, replacements);
});
Emitter.writeTemplate(writer, settings, ENUM_CLASS_FOOTER_TEMPLATE, replacements);
}
}
use of org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.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 org.apache.flink.shaded.jackson2.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);
}
Aggregations