com.fasterxml.jackson.databind.cfg.MapperBuilder Java Examples

The following examples show how to use com.fasterxml.jackson.databind.cfg.MapperBuilder. 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: ObjectMapperModule.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectMapper get()
{
    ObjectMapper mapper = objectMapper;
    if (mapper == null) {
        final GuiceAnnotationIntrospector guiceIntrospector = new GuiceAnnotationIntrospector();
        AnnotationIntrospector defaultAI = new JacksonAnnotationIntrospector();
        MapperBuilder<?,?> builder = JsonMapper.builder()
                .injectableValues(new GuiceInjectableValues(injector))
                .annotationIntrospector(new AnnotationIntrospectorPair(guiceIntrospector, defaultAI))
                .addModules(modulesToAdd);
        for (Provider<? extends Module> provider : providedModules) {
            builder = builder.addModule(provider.get());
        }
        mapper = builder.build();

      /*
  } else {
        // 05-Feb-2017, tatu: _Should_ be fine, considering instances are now (3.0) truly immutable.
      //    But if this turns out to be problematic, may need to consider addition of `copy()`
      //    back in databind
      mapper = mapper.copy();
      */
  }
  return mapper;
}
 
Example #2
Source File: TestSerializationInclusion.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
private void _testInclusion(MapperBuilder<?,?> builder) throws Exception
{
    ObjectMapper mapper = builder.changeDefaultPropertyInclusion(
            incl -> incl.withValueInclusion(JsonInclude.Include.NON_EMPTY))
            .build();
    String json = mapper.writeValueAsString(new Data());
    assertEquals("{}", json);
}
 
Example #3
Source File: BaseJaxbTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
protected MapperBuilder<?,?> getJaxbAndJacksonMapperBuilder()
{
    return JsonMapper.builder()
            .annotationIntrospector(new AnnotationIntrospectorPair(
                    new JaxbAnnotationIntrospector(),
                    new JacksonAnnotationIntrospector()));
}
 
Example #4
Source File: GenerateWithMixinsTest.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
public void _testIssue51(MapperBuilder<?,?> mapperB) throws Exception
{
    SampleObject sampleObject = new SampleObject("field1", 2, "field3".getBytes());
    ObjectMapper mapper = mapperB
            .addMixIn(SampleObject.class, IgnoreField3MixIn.class)
            .build();
    String json = mapper.writeValueAsString(sampleObject);
    assertEquals(aposToQuotes("{'field1':'field1','field2':2}"), json);
}
 
Example #5
Source File: ModuleTestBase.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
protected MapperBuilder<?,?> builderWithModule() {
    return builderWithModule(false);
}
 
Example #6
Source File: ModuleTestBase.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
protected MapperBuilder<?,?> builderWithModule(boolean absentsAsNulls)
{
    return JsonMapper.builder()
            .addModule(new GuavaModule()
                    .configureAbsentsAsNulls(absentsAsNulls));
}
 
Example #7
Source File: ModuleTestBase.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
protected MapperBuilder<?,?> mapperBuilder() {
    return JsonMapper.builder()
            .addModule(new EclipseCollectionsModule());
}
 
Example #8
Source File: ModuleTestBase.java    From jackson-modules-java8 with Apache License 2.0 4 votes vote down vote up
protected static MapperBuilder<?,?> newMapperBuilder() {
    return JsonMapper.builder()
            .addModule(new JavaTimeModule());
}
 
Example #9
Source File: ModuleTestBase.java    From jackson-modules-java8 with Apache License 2.0 4 votes vote down vote up
protected static MapperBuilder<?,?> newMapperBuilder(TimeZone tz) {
    return JsonMapper.builder()
            .defaultTimeZone(tz)
            .addModule(new JavaTimeModule());
}
 
Example #10
Source File: BaseJaxbTest.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
protected MapperBuilder<?,?> objectMapperBuilder()
{
    return JsonMapper.builder();
}
 
Example #11
Source File: BaseJaxbTest.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
protected MapperBuilder<?,?> getJaxbMapperBuilder()
{
    return JsonMapper.builder()
            .annotationIntrospector(new JaxbAnnotationIntrospector());
}
 
Example #12
Source File: BaseJaxbTest.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
protected MapperBuilder<?,?> getJacksonAndJaxbMapperBuilder()
{
    return JsonMapper.builder()
            .annotationIntrospector(new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(),
                    new JaxbAnnotationIntrospector()));
}
 
Example #13
Source File: AfterburnerTestBase.java    From jackson-modules-base with Apache License 2.0 4 votes vote down vote up
protected static MapperBuilder<?,?> afterburnerMapperBuilder() {
    return JsonMapper.builder()
            .addModule(new AfterburnerModule());
}