Search in sources :

Example 1 with SerializerProvider

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;
    }
}
Also used : SerializerBase(org.codehaus.jackson.map.ser.std.SerializerBase) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.codehaus.jettison.json.JSONException) StringCodec(com.datatorrent.api.StringCodec) Version(org.codehaus.jackson.Version) JsonGenerator(org.codehaus.jackson.JsonGenerator) JSONObject(org.codehaus.jettison.json.JSONObject) SerializerProvider(org.codehaus.jackson.map.SerializerProvider) Map(java.util.Map) BeanMap(org.apache.commons.beanutils.BeanMap) HashMap(java.util.HashMap) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Aggregations

StringCodec (com.datatorrent.api.StringCodec)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 BeanMap (org.apache.commons.beanutils.BeanMap)1 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)1 JsonGenerator (org.codehaus.jackson.JsonGenerator)1 JsonProcessingException (org.codehaus.jackson.JsonProcessingException)1 Version (org.codehaus.jackson.Version)1 SerializerProvider (org.codehaus.jackson.map.SerializerProvider)1 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)1 SerializerBase (org.codehaus.jackson.map.ser.std.SerializerBase)1 JSONException (org.codehaus.jettison.json.JSONException)1 JSONObject (org.codehaus.jettison.json.JSONObject)1