Search in sources :

Example 1 with DeserializationConfig

use of org.codehaus.jackson.map.DeserializationConfig in project ANNIS by korpling.

the class AnnisRunner method doAnnotations.

public void doAnnotations(String doListValues) {
    boolean listValues = "values".equals(doListValues);
    List<AnnisAttribute> annotations = queryDao.listAnnotations(getCorpusList(), listValues, true);
    try {
        ObjectMapper om = new ObjectMapper();
        AnnotationIntrospector ai = new JaxbAnnotationIntrospector();
        DeserializationConfig config = om.getDeserializationConfig().withAnnotationIntrospector(ai);
        om.setDeserializationConfig(config);
        om.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
        System.out.println(om.writeValueAsString(annotations));
    } catch (IOException ex) {
        log.error("problems with writing result", ex);
    }
}
Also used : AnnisAttribute(annis.service.objects.AnnisAttribute) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector) AnnotationIntrospector(org.codehaus.jackson.map.AnnotationIntrospector) DeserializationConfig(org.codehaus.jackson.map.DeserializationConfig) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector)

Example 2 with DeserializationConfig

use of org.codehaus.jackson.map.DeserializationConfig in project ovirt-engine by oVirt.

the class V3CustomObjectMapper method addSerializationConfig.

protected V3CustomObjectMapper addSerializationConfig() {
    // We need the instrospector that takes into account the JAXB annotations,
    // both for the serializer and for the deserializer:
    JaxbAnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // Configure the serializer:
    SerializationConfig serCfg = getSerializationConfig().withAnnotationIntrospector(introspector);
    setSerializationConfig(serCfg);
    // Configure the deserializer:
    DeserializationConfig deserCfg = getDeserializationConfig().withAnnotationIntrospector(introspector);
    setDeserializationConfig(deserCfg);
    return this;
}
Also used : SerializationConfig(org.codehaus.jackson.map.SerializationConfig) DeserializationConfig(org.codehaus.jackson.map.DeserializationConfig) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector)

Example 3 with DeserializationConfig

use of org.codehaus.jackson.map.DeserializationConfig in project ovirt-engine by oVirt.

the class CustomObjectMapper method addSerializationConfig.

protected CustomObjectMapper addSerializationConfig() {
    // We need the instrospector that takes into account the JAXB annotations,
    // both for the serializer and for the deserializer:
    JaxbAnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
    // Configure the serializer:
    SerializationConfig serCfg = getSerializationConfig().withAnnotationIntrospector(introspector);
    setSerializationConfig(serCfg);
    // Configure the deserializer:
    DeserializationConfig deserCfg = getDeserializationConfig().withAnnotationIntrospector(introspector);
    setDeserializationConfig(deserCfg);
    return this;
}
Also used : SerializationConfig(org.codehaus.jackson.map.SerializationConfig) DeserializationConfig(org.codehaus.jackson.map.DeserializationConfig) JaxbAnnotationIntrospector(org.codehaus.jackson.xc.JaxbAnnotationIntrospector)

Example 4 with DeserializationConfig

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

the class PropertyJsonSerializer method deserialize.

@Override
public T deserialize(byte[] bytes) throws PropertyStoreException {
    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 value = mapper.readValue(bais, _clazz);
        return value;
    } catch (Exception e) {
        LOG.error("Error during deserialization of 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)

Example 5 with DeserializationConfig

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

the class ZNRecordSerializer method deserialize.

@Override
public Object deserialize(byte[] bytes) {
    if (bytes == null || bytes.length == 0) {
        // reading a parent/null node
        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 {
        // decompress the data if its already compressed
        if (GZipCompressionUtil.isCompressed(bytes)) {
            byte[] uncompressedBytes = GZipCompressionUtil.uncompress(bais);
            bais = new ByteArrayInputStream(uncompressedBytes);
        }
        ZNRecord zn = mapper.readValue(bais, ZNRecord.class);
        return zn;
    } catch (Exception e) {
        logger.error("Exception during deserialization of 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) ZNRecord(org.apache.helix.ZNRecord) IOException(java.io.IOException) 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