private static Pair createJaxbJacksonAnnotationIntrospector() { final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(); final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector); } }
@Override public boolean isIgnorableField(AnnotatedField f) { return _isIgnorable(f); }
@Override public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config, AnnotatedClass ac, JavaType baseType) { return _findTypeResolver(config, ac, baseType); }
return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder();
return null; b = _constructStdTypeResolverBuilder();
return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder();
return null; b = _constructStdTypeResolverBuilder();
/** * Customized {@link TypeResolverBuilder} that provides type resolver builders * used with so-called "default typing" * (see {@link ObjectMapper#enableDefaultTyping()} for details). *<p> * Type resolver construction is based on configuration: implementation takes care * of only providing builders in cases where type information should be applied. * This is important since build calls may be sent for any and all types, and * type information should NOT be applied to all of them. */ public static class DefaultTypeResolverBuilder extends StdTypeResolverBuilder { /** * Definition of what types is this default typer valid for. */ protected final DefaultTyping _appliesFor; public DefaultTypeResolverBuilder(DefaultTyping t) { _appliesFor = t; } @Override public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes, BeanProperty property) { return useForType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes, property) : null; } @Override
@Override public boolean hasIgnoreMarker(AnnotatedMember m) { return _isIgnorable(m); }
/** * Since 1.7, it is possible to use {@link JsonTypeInfo} from a property too. */ @Override public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config, AnnotatedMember am, JavaType baseType) { /* As per definition of @JsonTypeInfo, should only apply to contents of container * (collection, map) types, not container types themselves: */ if (baseType.isContainerType()) return null; // No per-member type overrides (yet) return _findTypeResolver(config, am, baseType); }
return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder();
/** * Customized {@link TypeResolverBuilder} that provides type resolver builders * used with so-called "default typing" * (see {@link ObjectMapper#enableDefaultTyping()} for details). *<p> * Type resolver construction is based on configuration: implementation takes care * of only providing builders in cases where type information should be applied. * This is important since build calls may be sent for any and all types, and * type information should NOT be applied to all of them. */ public static class DefaultTypeResolverBuilder extends StdTypeResolverBuilder { /** * Definition of what types is this default typer valid for. */ protected final DefaultTyping _appliesFor; public DefaultTypeResolverBuilder(DefaultTyping t) { _appliesFor = t; } @Override public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, JavaType baseType, Collection<NamedType> subtypes, BeanProperty property) { return useForType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes, property) : null; } @Override
@Override public boolean isIgnorableMethod(AnnotatedMethod m) { return _isIgnorable(m); }
/** * Since 1.7, it is possible to use {@link JsonTypeInfo} from a property too. */ @Override public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config, AnnotatedMember am, JavaType containerType) { /* First: let's ensure property is a container type: caller should have * verified but just to be sure */ if (!containerType.isContainerType()) { throw new IllegalArgumentException("Must call method with a container type (got "+containerType+")"); } return _findTypeResolver(config, am, containerType); }
public JacksonJsonProvider create(Iterable<? extends Module> modules) { ObjectMapper mapper = new ObjectMapper(); /* This is what MapperConfigurator would do to a default ObjectMapper */ AnnotationIntrospector intr = AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector()); mapper.setDeserializationConfig(mapper.getDeserializationConfig().withAnnotationIntrospector(intr)); mapper.setSerializationConfig(mapper.getSerializationConfig().withAnnotationIntrospector(intr)); /* In the absence of a specific annotation for @JsonSerialize(include), ignore null fields when serializing */ mapper.setSerializationInclusion(Inclusion.NON_NULL); for (Module module : modules) { mapper.registerModule(module); } mapper.registerModule(new GuavaIterableCapableModule()); JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider(mapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS); // Make sure we only rely on annotations for de-/serialization provider.configure(SerializationConfig.Feature.AUTO_DETECT_GETTERS, false); provider.configure(SerializationConfig.Feature.AUTO_DETECT_FIELDS, false); provider.configure(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, false); provider.configure(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, false); return provider; } }
@Override public boolean isIgnorableConstructor(AnnotatedConstructor c) { return _isIgnorable(c); }
@Override public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config, AnnotatedClass ac, JavaType baseType) { return _findTypeResolver(config, ac, baseType); }
@Override public ObjectMapper locateMapper(Class<?> type, MediaType mediaType) { ObjectMapper mapper = super.locateMapper(type, mediaType); AnnotationIntrospector introspector = new AnnotationIntrospector.Pair( new JaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector() ); mapper.setAnnotationIntrospector(introspector); //mapper.setSerializationInclusion(Inclusion.NON_NULL); return mapper; } }
@Override public boolean isIgnorableConstructor(AnnotatedConstructor c) { return _isIgnorable(c); }
/** * Since 1.7, it is possible to use {@link JsonTypeInfo} from a property too. */ @Override public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config, AnnotatedMember am, JavaType baseType) { /* As per definition of @JsonTypeInfo, should only apply to contents of container * (collection, map) types, not container types themselves: */ if (baseType.isContainerType()) return null; // No per-member type overrides (yet) return _findTypeResolver(config, am, baseType); }