protected AnnotationIntrospector _resolveIntrospector(Annotations ann) { switch (ann) { case JACKSON: return new JacksonAnnotationIntrospector(); case JAXB: /* For this, need to use indirection just so that error occurs * when we get here, and not when this class is being loaded */ try { if (_jaxbIntrospectorClass == null) { _jaxbIntrospectorClass = JaxbAnnotationIntrospector.class; } return _jaxbIntrospectorClass.newInstance(); } catch (Exception e) { throw new IllegalStateException("Failed to instantiate JaxbAnnotationIntrospector: "+e.getMessage(), e); } default: throw new IllegalStateException(); } } }
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() { final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector); } }
public static ObjectMapper getMapper() { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector aipair = new AnnotationIntrospectorPair ( new JaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector() ); mapper.setAnnotationIntrospector(aipair); //REMOVE: mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, true); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); return mapper; } }
/** * 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 implements java.io.Serializable { private static final long serialVersionUID = 1L; /** * 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) { return useForType(baseType) ? super.buildTypeDeserializer(config, baseType, subtypes) : null;
/** * Annotation introspector to use for serialization process * is configured separately for serialization and deserialization purposes */ public JaxbJacksonObjectMapper() { final AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); super.getDeserializationConfig() .with(introspector); super.getSerializationConfig() .with(introspector); } }
protected AnnotationIntrospector _resolveIntrospector(Annotations ann) { switch (ann) { case JACKSON: return new JacksonAnnotationIntrospector(); case JAXB: /* For this, need to use indirection just so that error occurs * when we get here, and not when this class is being loaded */ try { if (_jaxbIntrospectorClass == null) { _jaxbIntrospectorClass = JaxbAnnotationIntrospector.class; } return _jaxbIntrospectorClass.newInstance(); } catch (Exception e) { throw new IllegalStateException("Failed to instantiate JaxbAnnotationIntrospector: "+e.getMessage(), e); } default: throw new IllegalStateException(); } } }
JacksonAnnotationIntrospector ignoreJsonTypeInfoIntrospector = new JacksonAnnotationIntrospector() { @Override protected TypeResolverBuilder<?> _findTypeResolver( MapperConfig<?> config, Annotated ann, JavaType baseType) { if (!ann.hasAnnotation(JsonTypeInfo.class)) { return super._findTypeResolver(config, ann, baseType); } return null; } }; mapper.setAnnotationIntrospector(ignoreJsonTypeInfoIntrospector);
protected static void initialize() { objectMapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addAbstractTypeMapping(Page.class, PageResponse.class); objectMapper.registerModule(module); AnnotationIntrospector introspector = new JacksonAnnotationIntrospector(); objectMapper.setAnnotationIntrospector(introspector); objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); objectMapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, false); }
public JacksonJsonMapper() { mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector pair = AnnotationIntrospectorPair.create(primary, secondary); mapper.setAnnotationIntrospector(pair); }
private static ObjectMapper getMapper() { ObjectMapper jacksonMapper = new ObjectMapper(); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); jacksonMapper.setAnnotationIntrospector(primary); jacksonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); jacksonMapper.registerModule(new MrBeanModule()); return jacksonMapper; } }
private static ObjectMapper withScalaSupport(ObjectMapper objectMapper) { objectMapper .registerModule(new DefaultScalaModule()) .setAnnotationIntrospector(new AnnotationIntrospectorPair( ScalaAnnotationIntrospector$.MODULE$, new JacksonAnnotationIntrospector())); return objectMapper; }
public static ObjectMapper createDefaultMapper() { final ObjectMapper result = new ObjectMapper(); result.configure(SerializationFeature.INDENT_OUTPUT, true); result.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); result.setSerializationInclusion(JsonInclude.Include.NON_NULL); result.setAnnotationIntrospector(AnnotationIntrospector.pair( new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()), new JacksonAnnotationIntrospector() )); return result; } }
@VisibleForTesting static ObjectMapper createConjureParserObjectMapper() { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()) .registerModule(new Jdk8Module()) .setAnnotationIntrospector( AnnotationIntrospector.pair( new KebabCaseEnforcingAnnotationInspector(), // needs to come first. new JacksonAnnotationIntrospector())); mapper.enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION); return mapper; } }
public JacksonContextResolver() { mapper = new ObjectMapper(); mapper.enable(MapperFeature.USE_WRAPPER_NAME_AS_PROPERTY_NAME); mapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector(mapper.getTypeFactory()))); mapper.setSerializationInclusion(Include.NON_NULL); }
public ClientObjectMapperContextResolver() { objectMapper = new ObjectMapper(); JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule(); objectMapper.registerModule(jaxbAnnotationModule); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()); AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospectorPair(jacksonIntrospector, jaxbIntrospector); objectMapper.setAnnotationIntrospector(pair); objectMapper.setSerializationInclusion(Include.NON_NULL); }
public ObjectMapperContextResolver() { objectMapper = new ObjectMapper(); JaxbAnnotationModule jaxbAnnotationModule = new JaxbAnnotationModule(); objectMapper.registerModule(jaxbAnnotationModule); objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()); AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospectorPair(jacksonIntrospector, jaxbIntrospector); objectMapper.setAnnotationIntrospector(pair); objectMapper.setSerializationInclusion(Include.NON_NULL); }
/** * Constructs a {@code JacksonObjectMapperProvider} with a custom object mapper. */ public JacksonObjectMapperProvider() { objectMapper = new ObjectMapper(); objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JacksonAnnotationIntrospector(), new JaxbAnnotationIntrospector())); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); }
public JacksonJaxbJsonProvider() { super(); objectMapper.setAnnotationIntrospector(AnnotationIntrospector.pair(new JaxbAnnotationIntrospector(objectMapper.getTypeFactory()), new JacksonAnnotationIntrospector())); }
public static ObjectMapper createObjectMapperWithIntroSpectors() { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primaryIntrospector = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondaryIntrospector = new JaxbAnnotationIntrospector(mapper.getTypeFactory()); AnnotationIntrospector introspector = new AnnotationIntrospectorPair(primaryIntrospector, secondaryIntrospector); mapper.getDeserializationConfig().withAppendedAnnotationIntrospector(introspector); mapper.getSerializationConfig().withAppendedAnnotationIntrospector(introspector); return mapper; }
@Override public void setupModule(final SetupContext context) { super.setupModule(context); context.addBeanDeserializerModifier(new ThreadLocalBuilderBeanDeserializerModifier()); context.insertAnnotationIntrospector( new AnnotationIntrospectorPair( new JacksonAnnotationIntrospector(), new BuilderAnnotationIntrospector())); }