Search in sources :

Example 6 with DeserializationConfig

use of org.codehaus.jackson.map.DeserializationConfig in project helix by apache.

the class JacksonPayloadSerializer method deserialize.

@Override
public <T> T deserialize(final Class<T> clazz, final byte[] bytes) {
    if (bytes == null || bytes.length == 0) {
        return null;
    }
    ObjectMapper mapper = new ObjectMapper();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
    deserializationConfig.set(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, true);
    deserializationConfig.set(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, true);
    deserializationConfig.set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true);
    try {
        T payload = mapper.readValue(bais, clazz);
        return payload;
    } catch (Exception e) {
        logger.error("Exception during deserialization of payload bytes: " + new String(bytes), e);
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DeserializationConfig(org.codehaus.jackson.map.DeserializationConfig) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) HelixException(org.apache.helix.HelixException)

Aggregations

DeserializationConfig (org.codehaus.jackson.map.DeserializationConfig)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HelixException (org.apache.helix.HelixException)3 JaxbAnnotationIntrospector (org.codehaus.jackson.xc.JaxbAnnotationIntrospector)3 IOException (java.io.IOException)2 SerializationConfig (org.codehaus.jackson.map.SerializationConfig)2 AnnisAttribute (annis.service.objects.AnnisAttribute)1 ZNRecord (org.apache.helix.ZNRecord)1 AnnotationIntrospector (org.codehaus.jackson.map.AnnotationIntrospector)1