use of org.codehaus.jackson.map.SerializerProvider in project apex-core by apache.
the class StramWebServices method init.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void init() {
//clear content type
httpResponse.setContentType(null);
if (!initialized) {
Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
StringCodecs.loadConverters(codecs);
if (codecs != null) {
SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
try {
final StringCodec<Object> codec = (StringCodec<Object>) entry.getValue().newInstance();
sm.addSerializer(new SerializerBase(entry.getKey()) {
@Override
public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeString(codec.toString(value));
}
});
} catch (Exception ex) {
LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
}
}
objectMapper.registerModule(sm);
}
initialized = true;
}
}
Aggregations