Search in sources :

Example 16 with AfterburnerModule

use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project oap by oaplatform.

the class Binder method initialize.

private static ObjectMapper initialize(ObjectMapper mapper, boolean defaultTyping, boolean nonNullInclusion, boolean skipInputNulls) {
    if (mapper instanceof XmlMapper) {
        ((XmlMapper) mapper).setDefaultUseWrapper(false);
        ((XmlMapper) mapper).configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
    }
    AnnotationIntrospector introspector = new JacksonAnnotationIntrospector();
    mapper.getDeserializationConfig().with(introspector);
    mapper.getSerializationConfig().with(introspector);
    mapper.registerModule(new AfterburnerModule());
    mapper.registerModule(new Jdk8Module().configureAbsentsAsNulls(true));
    mapper.registerModule(new JodaModule());
    mapper.registerModule(new ExtModule());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.DEFAULT));
    mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
    mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.disable(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS);
    mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    // todo remove after kernel cleanup
    mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
    if (skipInputNulls)
        mapper.setDefaultSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
    if (!nonNullInclusion)
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    modules.forEach(mapper::registerModule);
    if (defaultTyping)
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
    return mapper;
}
Also used : JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) ParameterNamesModule(com.fasterxml.jackson.module.paramnames.ParameterNamesModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) JacksonAnnotationIntrospector(com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector) AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) ExtModule(oap.json.ext.ExtModule)

Example 17 with AfterburnerModule

use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project core-ng-project by neowu.

the class JSONMapper method createObjectMapper.

private static ObjectMapper createObjectMapper() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    mapper.registerModule(new JavaTimeModule());
    mapper.registerModule(new AfterburnerModule());
    mapper.setDateFormat(new StdDateFormat());
    mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.configure(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME, true);
    mapper.setAnnotationIntrospector(new JSONAnnotationIntrospector());
    return mapper;
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) StdDateFormat(com.fasterxml.jackson.databind.util.StdDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 18 with AfterburnerModule

use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project jackson-module-afterburner by FasterXML.

the class VLTBet method testIssue.

public void testIssue() throws Exception {
    // create this ridiculously complicated object
    ItemData data = new ItemData();
    data.denomination = 100;
    Item item = new Item();
    item.data = data;
    item.productId = 123;
    List<Item> itemList = new ArrayList<Item>();
    itemList.add(item);
    PlaceOrderRequest order = new PlaceOrderRequest();
    order.orderId = 68723496;
    order.userId = "123489043";
    order.amount = 250;
    order.status = "placed";
    order.items = itemList;
    final Date now = new Date(999999L);
    order.createdAt = now;
    order.updatedAt = now;
    ObjectMapper vanillaMapper = new ObjectMapper();
    ObjectMapper abMapper = new ObjectMapper();
    abMapper.registerModule(new AfterburnerModule());
    // First: ensure that serialization produces identical output
    String origJson = vanillaMapper.writerWithDefaultPrettyPrinter().writeValueAsString(order);
    String abJson = abMapper.writerWithDefaultPrettyPrinter().writeValueAsString(order);
    assertEquals(origJson, abJson);
    // Then read the string and turn it back into an object
    // this will cause an exception unless the AfterburnerModule is commented out
    order = abMapper.readValue(abJson, PlaceOrderRequest.class);
    assertNotNull(order);
    assertEquals(250, order.amount);
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 19 with AfterburnerModule

use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project jackson-module-afterburner by FasterXML.

the class TestDeserializePerf method main.

public static void main(String[] args) throws Exception {
    // JsonFactory f = new org.codehaus.jackson.smile.SmileFactory();
    JsonFactory f = new JsonFactory();
    ObjectMapper mapperSlow = new ObjectMapper(f);
    ObjectMapper mapperFast = new ObjectMapper(f);
    // !!! TEST -- to get profile info, comment out:
    // mapperSlow.registerModule(new AfterburnerModule());
    mapperFast.registerModule(new AfterburnerModule());
    new TestDeserializePerf().testWith(mapperSlow, mapperFast);
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with AfterburnerModule

use of com.fasterxml.jackson.module.afterburner.AfterburnerModule in project ninja by ninjaframework.

the class XmlMapperProvider method get.

@Override
public XmlMapper get() {
    JacksonXmlModule module = new JacksonXmlModule();
    // Check out: https://github.com/FasterXML/jackson-dataformat-xml
    // setDefaultUseWrapper produces more similar output to
    // the Json output. You can change that with annotations in your
    // models.
    module.setDefaultUseWrapper(false);
    XmlMapper xmlMapper = new XmlMapper(module);
    xmlMapper.registerModule(new AfterburnerModule());
    return xmlMapper;
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JacksonXmlModule(com.fasterxml.jackson.dataformat.xml.JacksonXmlModule) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)21 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)18 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)4 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)4 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)4 SchemaPath (org.apache.drill.common.expression.SchemaPath)4 Path (org.apache.hadoop.fs.Path)4 JacksonPayloadSerializer (co.elastic.apm.report.serialize.JacksonPayloadSerializer)3 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)3 MediaContent (data.media.MediaContent)3 IOException (java.io.IOException)3 SerFeatures (serializers.SerFeatures)3 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)2 Stopwatch (com.google.common.base.Stopwatch)2 InputStream (java.io.InputStream)2 ParquetFileMetadata (org.apache.drill.exec.store.parquet.metadata.MetadataBase.ParquetFileMetadata)2 ColumnTypeMetadata_v4 (org.apache.drill.exec.store.parquet.metadata.Metadata_V4.ColumnTypeMetadata_v4)2 FileMetadata (org.apache.drill.exec.store.parquet.metadata.Metadata_V4.FileMetadata)2 MetadataSummary (org.apache.drill.exec.store.parquet.metadata.Metadata_V4.MetadataSummary)2