com.fasterxml.jackson.module.afterburner.AfterburnerModule Java Examples

The following examples show how to use com.fasterxml.jackson.module.afterburner.AfterburnerModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JSONBindingFactory.java    From cougar with Apache License 2.0 6 votes vote down vote up
public ObjectMapper createBaseObjectMapper() {
	ObjectMapper mapper = new ObjectMapper();
	JSONDateFormat jdf=new JSONDateFormat();

	mapper.setDateFormat(jdf);
	mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
       if (enableAfterburner) {
           AfterburnerModule module = new AfterburnerModule();
           module.setUseOptimizedBeanDeserializer(useOptimizedBeanDeserializer);
           module.setUseValueClassLoader(useValueClassLoader);
           mapper.registerModule(module);
       }

       applyNumericRangeBugfixes(mapper);
	return mapper;
}
 
Example #2
Source File: JacksonModule.java    From proteus with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure()
{

    ObjectMapper objectMapper = new ObjectMapper();

    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
    objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
    objectMapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH,true);
    objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    objectMapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);

    objectMapper.registerModule(new MoneyModule())
            .registerModule(new AfterburnerModule())
            .registerModule(new Jdk8Module());

    this.bind(ObjectMapper.class).toInstance(objectMapper);

}
 
Example #3
Source File: JacksonModule.java    From proteus with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure()
{
    ObjectMapper objectMapper = new ObjectMapper();

    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
    objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
    objectMapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
    objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    objectMapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);

    objectMapper.registerModule(new AfterburnerModule());
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(new ParameterNamesModule());

    this.bind(ObjectMapper.class).toInstance(objectMapper);
}
 
Example #4
Source File: LogicalPlanPersistence.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
public LogicalPlanPersistence(SabotConfig conf, ScanResult scanResult) {
  mapper = new ObjectMapper();

  SimpleModule deserModule = new SimpleModule("LogicalExpressionDeserializationModule")
      .addDeserializer(LogicalExpression.class, new LogicalExpression.De())
      .addDeserializer(SchemaPath.class, new SchemaPath.De())
      .addDeserializer(FieldReference.class, new FieldReference.De());

  mapper.registerModule(new AfterburnerModule());
  mapper.registerModule(deserModule);
  mapper.enable(SerializationFeature.INDENT_OUTPUT);
  mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
  mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
  mapper.configure(Feature.ALLOW_COMMENTS, true);
  registerSubtypes(LogicalOperatorBase.getSubTypes(scanResult));
  registerSubtypes(StoragePluginConfigBase.getSubTypes(scanResult));
  registerSubtypes(FormatPluginConfigBase.getSubTypes(scanResult));
}
 
Example #5
Source File: TestCreatorsDelegating.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testWithCtorAndDelegate() throws Exception
{
    ObjectMapper mapper = JsonMapper.builder()
            .injectableValues(new InjectableValues.Std()
                    .addValue(String.class, "Pooka"))
            .addModule(new AfterburnerModule())
            .build();
    CtorBean711 bean = null;
    try {
        bean = mapper.readValue("38", CtorBean711.class);
    } catch (JsonMappingException e) {
        fail("Did not expect problems, got: "+e.getMessage());
    }
    assertEquals(38, bean.age);
    assertEquals("Pooka", bean.name);
}
 
Example #6
Source File: TestCreatorsDelegating.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testWithFactoryAndDelegate() throws Exception
{
    ObjectMapper mapper = JsonMapper.builder()
            .injectableValues(new InjectableValues.Std()
                    .addValue(String.class, "Fygar"))
            .addModule(new AfterburnerModule())
            .build();
    FactoryBean711 bean = null;
    try {
        bean = mapper.readValue("38", FactoryBean711.class);
    } catch (JsonMappingException e) {
        fail("Did not expect problems, got: "+e.getMessage());
    }
    assertEquals(38, bean.age);
    assertEquals("Fygar", bean.name1);
    assertEquals("Fygar", bean.name2);
}
 
Example #7
Source File: TestCollectionDeser.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testUnwrapSingleArray() throws Exception
{
    final ObjectMapper mapper = JsonMapper.builder()
            .enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
            .addModule(new AfterburnerModule())
            .build();
    final Integer intValue = mapper.readValue("[ 1 ]", Integer.class);
    assertEquals(Integer.valueOf(1), intValue);

    final String strValue = mapper.readValue("[ \"abc\" ]", String.class);
    assertEquals("abc", strValue);

    // and then via POJO. First, array of POJOs
    IntBean b1 = mapper.readValue(aposToQuotes("[{ 'value' : 123 }]"), IntBean.class);
    assertNotNull(b1);
    assertEquals(123, b1.value);

    // and then array of ints within POJO
    IntBean b2 = mapper.readValue(aposToQuotes("{ 'value' : [ 123 ] }"), IntBean.class);
    assertNotNull(b2);
    assertEquals(123, b2.value);
}
 
Example #8
Source File: ManualDatabindPerf.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception
{
    if (args.length != 0) {
        System.err.println("Usage: java ...");
        System.exit(1);
    }
    ObjectMapper vanilla = new ObjectMapper();
    ObjectMapper burnt = JsonMapper.builder()
            .addModule(new AfterburnerModule())
            .build();

    /*
    TestPojo input = new TestPojo(1245, -99, "Billy-Bob",
            new Value(27, 116));

    new ManualDatabindPerf().test(vanilla, burnt, input, TestPojo.class);
    */

    MediaItem media = MediaItem.buildItem();
    new ManualDatabindPerf().test(vanilla, burnt, media, MediaItem.class);
}
 
Example #9
Source File: PerfGsonSerDe.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup() {
   gson = new GsonBuilder().create();

   abmapper.registerModule(new AfterburnerModule());
   mpmapper.registerModule(new AfterburnerModule());

   Map<String,Object> attrs = ImmutableMap.<String,Object>of(
      "test1", Integer.valueOf(1),
      "test2", "this is a string",
      "test3", Long.valueOf(1L)
   );

   MessageBody payload = MessageBody.buildMessage("test", attrs);
   Address src = Address.deviceAddress("test", UUID.randomUUID());
   Address dst = Address.deviceAddress("test", UUID.randomUUID());

   msg = PlatformMessage.buildRequest(payload, src, dst).create();
}
 
Example #10
Source File: JSON.java    From rapidoid with Apache License 2.0 6 votes vote down vote up
private static ObjectMapper prettyMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL);
	mapper.configure(SerializationFeature.INDENT_OUTPUT, true);

	mapper.registerModule(tuuidModule());

	if (!Env.dev()) {
		mapper.registerModule(new AfterburnerModule());
	}

	DefaultPrettyPrinter pp = new DefaultPrettyPrinter();
	pp = pp.withObjectIndenter(new DefaultIndenter("  ", "\n"));

	mapper.setDefaultPrettyPrinter(pp);

	return mapper;
}
 
Example #11
Source File: SyncopeXmlMapper.java    From syncope with Apache License 2.0 5 votes vote down vote up
public SyncopeXmlMapper() {
    super();

    registerModule(new AfterburnerModule());

    registerModule(new JavaTimeModule());
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);

    configOverride(List.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
    configOverride(Set.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
    configOverride(Map.class).setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.AS_EMPTY));
}
 
Example #12
Source File: GraphQLIntegrationTest.java    From rsocket-rpc-java with Apache License 2.0 5 votes vote down vote up
private static Unmarshaller<GraphQLDataFetchers.Book> unmarshaller() {
  ObjectMapper mapper = new ObjectMapper();
  mapper.registerModule(new AfterburnerModule());
  return byteBuf -> {
    try {
      InputStream byteBufInputStream = new ByteBufInputStream(byteBuf);
      Map map = mapper.readValue(byteBufInputStream, Map.class);
      Object bookById = map.get("bookById");
      return mapper.convertValue(bookById, GraphQLDataFetchers.Book.class);
    } catch (Exception e) {
      throw Exceptions.propagate(e);
    }
  };
}
 
Example #13
Source File: ObjectMapperBuilderTest.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Test(enabled = false)
public void testAfterburnerModule() throws JsonProcessingException {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new AfterburnerModule());

    objectMapper.writeValueAsString(new TestObjectWIthJsonSerialize(new BigDecimal("870.04")));
}
 
Example #14
Source File: RawOfficeFloorMain.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Instantiate.
 *
 * @param serverLocation    {@link HttpServerLocation}.
 * @param serviceBufferPool {@link StreamBufferPool}.
 */
public RawHttpServicerFactory(HttpServerLocation serverLocation,
		StreamBufferPool<ByteBuffer> serviceBufferPool) {
	super(serverLocation, false, new HttpRequestParserMetaData(100, 1000, 1000000), serviceBufferPool, null,
			null, true);
	this.objectMapper.registerModule(new AfterburnerModule());
}
 
Example #15
Source File: ObjectMappers.java    From roboslack with Apache License 2.0 5 votes vote down vote up
public static ObjectMapper newObjectMapper() {
    return new ObjectMapper().registerModule(new GuavaModule())
            .registerModule(new Jdk8Module().configureAbsentsAsNulls(true))
            .registerModule(new AfterburnerModule())
            .registerModule(new JavaTimeModule())
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
            .disable(DeserializationFeature.WRAP_EXCEPTIONS)
            .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
            .enable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);
}
 
Example #16
Source File: JacksonBaseEngine.java    From pippo with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Application application) {
    objectMapper = getObjectMapper();
    objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    objectMapper.setTimeZone(TimeZone.getDefault());
    objectMapper.registerModule(new AfterburnerModule());
}
 
Example #17
Source File: UsersJsonProvider.java    From java-json-benchmark with MIT License 5 votes vote down vote up
public UsersJsonProvider() {
    jacksonAfterburner.registerModule(new AfterburnerModule());

    jsonioStreamOptions.put(JsonReader.USE_MAPS, true);
    jsonioStreamOptions.put(JsonWriter.TYPE, false);

    // set johnson JsonReader (default is `JsonProvider.provider()`)
    javax.json.spi.JsonProvider johnzonProvider = new JsonProviderImpl();
    johnzon = new org.apache.johnzon.mapper.MapperBuilder()
        .setReaderFactory(johnzonProvider.createReaderFactory(Collections.emptyMap()))
        .setGeneratorFactory(johnzonProvider.createGeneratorFactory(Collections.emptyMap()))
        .setAccessModeName("field") // default is "strict-method" which doesn't work nicely with public attributes
        .build();
}
 
Example #18
Source File: IsolatedClassLoaderTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testBeanWithSeparateClassLoader() throws IOException {
    ObjectMapper mapper = JsonMapper.builder()
            .addModule(new AfterburnerModule())
            .build();

    Object bean = makeObjectFromIsolatedClassloader();
    String result = mapper.writeValueAsString(bean);
    assertEquals("{\"value\":\"some string\"}", result);
}
 
Example #19
Source File: TestCollectionDeser.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void testIntMethod() throws Exception
{
    final ObjectMapper mapper = JsonMapper.builder()
            .configure(MapperFeature.USE_GETTERS_AS_SETTERS, true)
            .addModule(new AfterburnerModule())
            .build();
    CollectionBean bean = mapper.readValue("{\"stuff\":[\"a\",\"b\"]}",
            CollectionBean.class);
    assertEquals(2, bean.x.size());
    assertEquals(TreeSet.class, bean.x.getClass());
}
 
Example #20
Source File: JSON.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
public static ObjectMapper newMapper() {
	ObjectMapper mapper = new ObjectMapper();
	mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL);
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

	mapper.registerModule(tuuidModule());

	if (!Env.dev()) {
		mapper.registerModule(new AfterburnerModule());
	}

	return mapper;
}
 
Example #21
Source File: XML.java    From rapidoid with Apache License 2.0 5 votes vote down vote up
public static XmlMapper newMapper() {
	XmlMapper mapper = new XmlMapper();
	mapper.setBase64Variant(Base64Variants.MODIFIED_FOR_URL);
	mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

	if (!Env.dev()) {
		mapper.registerModule(new AfterburnerModule());
	}

	return mapper;
}
 
Example #22
Source File: TestDeserializePerf.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
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);
        
        // !!! TEST -- to get profile info, comment out:
//        mapperSlow.registerModule(new AfterburnerModule());

        ObjectMapper mapperFast = JsonMapper.builder(f)
                .addModule(new AfterburnerModule())
                .build();
        new TestDeserializePerf().testWith(mapperSlow, mapperFast);
    }
 
Example #23
Source File: TestSerializePerf.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
    {
//        JsonFactory f = new org.codehaus.jackson.smile.SmileFactory();
        JsonFactory f = new JsonFactory();
        ObjectMapper mapperSlow = JsonMapper.builder(f)
        // !!! TEST -- to get profile info, comment out:
                .addModule(new AfterburnerModule())
                .build();

        ObjectMapper mapperFast = JsonMapper.builder(f)
                .addModule(new AfterburnerModule())
                .build();
        new TestSerializePerf().testWith(mapperSlow, mapperFast);
    }
 
Example #24
Source File: JSONMapper.java    From core-ng-project with Apache License 2.0 5 votes vote down vote up
private static ObjectMapper createObjectMapper() {
    return JsonMapper.builder()
                     .addModule(timeModule())
                     // disable value class loader to avoid jdk illegal reflection warning, requires JSON class/fields must be public
                     .addModule(new AfterburnerModule().setUseValueClassLoader(false))
                     .defaultDateFormat(new StdDateFormat())
                     // only auto detect field, and default visibility is public_only, refer to com.fasterxml.jackson.databind.introspect.VisibilityChecker.Std
                     .visibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, PUBLIC_ONLY))
                     .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
                     .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                     .annotationIntrospector(new JSONAnnotationIntrospector())
                     .deactivateDefaultTyping()
                     .build();
}
 
Example #25
Source File: SyncopeYAMLMapper.java    From syncope with Apache License 2.0 5 votes vote down vote up
public SyncopeYAMLMapper() {
    super();

    registerModule(new AfterburnerModule());

    registerModule(new JavaTimeModule());
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
Example #26
Source File: SyncopeObjectMapper.java    From syncope with Apache License 2.0 5 votes vote down vote up
public SyncopeObjectMapper() {
    super();

    registerModule(new AfterburnerModule());

    registerModule(new JavaTimeModule());
    configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
 
Example #27
Source File: JacksonConfiguration.java    From java-microservices-examples with Apache License 2.0 4 votes vote down vote up
@Bean
public AfterburnerModule afterburnerModule() {
    return new AfterburnerModule();
}
 
Example #28
Source File: JacksonConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
@Bean
public AfterburnerModule afterburnerModule() {
    return new AfterburnerModule();
}
 
Example #29
Source File: JacksonConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
@Bean
public AfterburnerModule afterburnerModule() {
    return new AfterburnerModule();
}
 
Example #30
Source File: JacksonConfiguration.java    From cubeai with Apache License 2.0 4 votes vote down vote up
@Bean
public AfterburnerModule afterburnerModule() {
    return new AfterburnerModule();
}