下面列出了com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair#com.fasterxml.jackson.databind.cfg.MapperBuilder 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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);
}
protected MapperBuilder<?,?> getJaxbAndJacksonMapperBuilder()
{
return JsonMapper.builder()
.annotationIntrospector(new AnnotationIntrospectorPair(
new JaxbAnnotationIntrospector(),
new JacksonAnnotationIntrospector()));
}
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);
}
protected MapperBuilder<?,?> builderWithModule() {
return builderWithModule(false);
}
protected MapperBuilder<?,?> builderWithModule(boolean absentsAsNulls)
{
return JsonMapper.builder()
.addModule(new GuavaModule()
.configureAbsentsAsNulls(absentsAsNulls));
}
protected MapperBuilder<?,?> mapperBuilder() {
return JsonMapper.builder()
.addModule(new EclipseCollectionsModule());
}
protected static MapperBuilder<?,?> newMapperBuilder() {
return JsonMapper.builder()
.addModule(new JavaTimeModule());
}
protected static MapperBuilder<?,?> newMapperBuilder(TimeZone tz) {
return JsonMapper.builder()
.defaultTimeZone(tz)
.addModule(new JavaTimeModule());
}
protected MapperBuilder<?,?> objectMapperBuilder()
{
return JsonMapper.builder();
}
protected MapperBuilder<?,?> getJaxbMapperBuilder()
{
return JsonMapper.builder()
.annotationIntrospector(new JaxbAnnotationIntrospector());
}
protected MapperBuilder<?,?> getJacksonAndJaxbMapperBuilder()
{
return JsonMapper.builder()
.annotationIntrospector(new AnnotationIntrospectorPair(new JacksonAnnotationIntrospector(),
new JaxbAnnotationIntrospector()));
}
protected static MapperBuilder<?,?> afterburnerMapperBuilder() {
return JsonMapper.builder()
.addModule(new AfterburnerModule());
}