/** * {@inheritDoc} */ public CustomObjectMapper() { super(); this.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false); this.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); this.setSerializationInclusion(JsonSerialize.Inclusion.NON_DEFAULT); this.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); this.setSerializationInclusion(JsonSerialize.Inclusion.NON_EMPTY); final AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make deserializer use JAXB annotations (only) this.setAnnotationIntrospector(introspector); // TODO leverage NamingStrategy to make reponse attributes more Java-like //this.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); }
public JsonModelSerializer(boolean doNullValues, Class<T> serializedType) { super(); objectMapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make serializer use JAXB annotations (only) SerializationConfig sc = objectMapper.getSerializationConfig().withAnnotationIntrospector(introspector); sc.with(SerializationConfig.Feature.INDENT_OUTPUT); if (!doNullValues) { sc.without(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES); sc.without(SerializationConfig.Feature.WRITE_EMPTY_JSON_ARRAYS); sc = sc.withSerializationInclusion(Inclusion.NON_EMPTY); } objectMapper.setSerializationConfig(sc); // if (!doNullValues) { // objectMapper.setSerializationInclusion(Inclusion.NON_EMPTY); // } }
private String buildJson(Object object) { ObjectMapper mapper = new ObjectMapper(); SerializationConfig serializationConfig = mapper.getSerializationConfig(); serializationConfig = serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); mapper.setSerializationConfig(serializationConfig); mapper.setAnnotationIntrospector(introspector); try { return mapper.writeValueAsString(object); } catch (IOException e) { log.warn("Can't marshal search criteria."); throw new RuntimeException("Failed inFolder build criteria json.", e); } }
public static void main(String[] args) throws JsonMappingException { ObjectMapper jsonMapper = new ObjectMapper(); AnnotationIntrospector introspector = new AnnotationIntrospector.Pair(new JaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector()); jsonMapper.setAnnotationIntrospector(introspector); JsonSchema schema = jsonMapper.generateJsonSchema(Testi.class); if(Testi.class.getAnnotation(XmlRootElement.class)!=null && !Testi.class.getAnnotation(XmlRootElement.class).name().equals("##default")) schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlRootElement.class).name()); else if(Testi.class.getAnnotation(XmlType.class)!=null && !Testi.class.getAnnotation(XmlType.class).name().equals("##default")) schema.getSchemaNode().put("name", Testi.class.getAnnotation(XmlType.class).name()); else schema.getSchemaNode().put("name", Testi.class.getSimpleName()); String schemaJson = schema.toString(); System.out.println(schemaJson); }
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass paramAnnotatedClass, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector) { HashMap localHashMap = new HashMap(); if (this._registeredSubtypes != null) { Class localClass = paramAnnotatedClass.getRawType(); Iterator localIterator = this._registeredSubtypes.iterator(); while (localIterator.hasNext()) { NamedType localNamedType = (NamedType)localIterator.next(); if (!localClass.isAssignableFrom(localNamedType.getType())) continue; _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType, paramMapperConfig, paramAnnotationIntrospector, localHashMap); } } _collectAndResolve(paramAnnotatedClass, new NamedType(paramAnnotatedClass.getRawType(), null), paramMapperConfig, paramAnnotationIntrospector, localHashMap); return new ArrayList(localHashMap.values()); }
protected <T extends AnnotatedMember> void removeIgnorableTypes(SerializationConfig paramSerializationConfig, BasicBeanDescription paramBasicBeanDescription, Map<String, T> paramMap) { if (paramMap.isEmpty()); while (true) { return; AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector(); Iterator localIterator = paramMap.entrySet().iterator(); HashMap localHashMap = new HashMap(); while (localIterator.hasNext()) { Class localClass = ((AnnotatedMember)((Map.Entry)localIterator.next()).getValue()).getRawType(); Boolean localBoolean = (Boolean)localHashMap.get(localClass); if (localBoolean == null) { localBoolean = localAnnotationIntrospector.isIgnorableType(((BasicBeanDescription)paramSerializationConfig.introspectClassAnnotations(localClass)).getClassInfo()); if (localBoolean == null) localBoolean = Boolean.FALSE; localHashMap.put(localClass, localBoolean); } if (!localBoolean.booleanValue()) continue; localIterator.remove(); } } }
public BasicBeanDescription forDeserialization(DeserializationConfig paramDeserializationConfig, JavaType paramJavaType, ClassIntrospector.MixInResolver paramMixInResolver) { boolean bool = paramDeserializationConfig.isAnnotationProcessingEnabled(); AnnotationIntrospector localAnnotationIntrospector = paramDeserializationConfig.getAnnotationIntrospector(); Class localClass = paramJavaType.getRawClass(); if (bool); while (true) { AnnotatedClass localAnnotatedClass = AnnotatedClass.construct(localClass, localAnnotationIntrospector, paramMixInResolver); localAnnotatedClass.resolveMemberMethods(getDeserializationMethodFilter(paramDeserializationConfig), true); localAnnotatedClass.resolveCreators(true); localAnnotatedClass.resolveFields(true); return new BasicBeanDescription(paramDeserializationConfig, paramJavaType, localAnnotatedClass); localAnnotationIntrospector = null; } }
public TypeDeserializer findTypeDeserializer(DeserializationConfig paramDeserializationConfig, JavaType paramJavaType, BeanProperty paramBeanProperty) { AnnotatedClass localAnnotatedClass = ((BasicBeanDescription)paramDeserializationConfig.introspectClassAnnotations(paramJavaType.getRawClass())).getClassInfo(); AnnotationIntrospector localAnnotationIntrospector = paramDeserializationConfig.getAnnotationIntrospector(); TypeResolverBuilder localTypeResolverBuilder = localAnnotationIntrospector.findTypeResolver(paramDeserializationConfig, localAnnotatedClass, paramJavaType); Collection localCollection; if (localTypeResolverBuilder == null) { localTypeResolverBuilder = paramDeserializationConfig.getDefaultTyper(paramJavaType); localCollection = null; if (localTypeResolverBuilder == null) return null; } else { localCollection = paramDeserializationConfig.getSubtypeResolver().collectAndResolveSubtypes(localAnnotatedClass, paramDeserializationConfig, localAnnotationIntrospector); } return localTypeResolverBuilder.buildTypeDeserializer(paramDeserializationConfig, paramJavaType, localCollection, paramBeanProperty); }
protected SettableBeanProperty constructSettableProperty(DeserializationConfig paramDeserializationConfig, BasicBeanDescription paramBasicBeanDescription, String paramString, AnnotatedField paramAnnotatedField) throws JsonMappingException { if (paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) paramAnnotatedField.fixAccess(); JavaType localJavaType1 = paramBasicBeanDescription.bindingsForBeanType().resolveType(paramAnnotatedField.getGenericType()); BeanProperty.Std localStd = new BeanProperty.Std(paramString, localJavaType1, paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedField); JavaType localJavaType2 = resolveType(paramDeserializationConfig, paramBasicBeanDescription, localJavaType1, paramAnnotatedField, localStd); if (localJavaType2 != localJavaType1) localStd = localStd.withType(localJavaType2); JsonDeserializer localJsonDeserializer = findDeserializerFromAnnotation(paramDeserializationConfig, paramAnnotatedField, localStd); JavaType localJavaType3 = modifyTypeByAnnotation(paramDeserializationConfig, paramAnnotatedField, localJavaType2, paramString); SettableBeanProperty.FieldProperty localFieldProperty = new SettableBeanProperty.FieldProperty(paramString, localJavaType3, (TypeDeserializer)localJavaType3.getTypeHandler(), paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedField); if (localJsonDeserializer != null) localFieldProperty.setValueDeserializer(localJsonDeserializer); AnnotationIntrospector.ReferenceProperty localReferenceProperty = paramDeserializationConfig.getAnnotationIntrospector().findReferenceType(paramAnnotatedField); if ((localReferenceProperty != null) && (localReferenceProperty.isManagedReference())) localFieldProperty.setManagedReferenceName(localReferenceProperty.getName()); return localFieldProperty; }
protected SettableBeanProperty constructSettableProperty(DeserializationConfig paramDeserializationConfig, BasicBeanDescription paramBasicBeanDescription, String paramString, AnnotatedMethod paramAnnotatedMethod) throws JsonMappingException { if (paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) paramAnnotatedMethod.fixAccess(); JavaType localJavaType1 = paramBasicBeanDescription.bindingsForBeanType().resolveType(paramAnnotatedMethod.getParameterType(0)); BeanProperty.Std localStd = new BeanProperty.Std(paramString, localJavaType1, paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedMethod); JavaType localJavaType2 = resolveType(paramDeserializationConfig, paramBasicBeanDescription, localJavaType1, paramAnnotatedMethod, localStd); if (localJavaType2 != localJavaType1) localStd = localStd.withType(localJavaType2); JsonDeserializer localJsonDeserializer = findDeserializerFromAnnotation(paramDeserializationConfig, paramAnnotatedMethod, localStd); JavaType localJavaType3 = modifyTypeByAnnotation(paramDeserializationConfig, paramAnnotatedMethod, localJavaType2, paramString); SettableBeanProperty.MethodProperty localMethodProperty = new SettableBeanProperty.MethodProperty(paramString, localJavaType3, (TypeDeserializer)localJavaType3.getTypeHandler(), paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedMethod); if (localJsonDeserializer != null) localMethodProperty.setValueDeserializer(localJsonDeserializer); AnnotationIntrospector.ReferenceProperty localReferenceProperty = paramDeserializationConfig.getAnnotationIntrospector().findReferenceType(paramAnnotatedMethod); if ((localReferenceProperty != null) && (localReferenceProperty.isManagedReference())) localMethodProperty.setManagedReferenceName(localReferenceProperty.getName()); return localMethodProperty; }
protected CreatorContainer findDeserializerCreators(DeserializationConfig paramDeserializationConfig, BasicBeanDescription paramBasicBeanDescription) throws JsonMappingException { boolean bool = paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS); CreatorContainer localCreatorContainer = new CreatorContainer(paramBasicBeanDescription, bool); AnnotationIntrospector localAnnotationIntrospector = paramDeserializationConfig.getAnnotationIntrospector(); if (paramBasicBeanDescription.getType().isConcrete()) { Constructor localConstructor = paramBasicBeanDescription.findDefaultConstructor(); if (localConstructor != null) { if (bool) ClassUtil.checkAndFixAccess(localConstructor); localCreatorContainer.setDefaultConstructor(localConstructor); } } VisibilityChecker localVisibilityChecker1 = paramDeserializationConfig.getDefaultVisibilityChecker(); if (!paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.AUTO_DETECT_CREATORS)) localVisibilityChecker1 = localVisibilityChecker1.withCreatorVisibility(JsonAutoDetect.Visibility.NONE); VisibilityChecker localVisibilityChecker2 = paramDeserializationConfig.getAnnotationIntrospector().findAutoDetectVisibility(paramBasicBeanDescription.getClassInfo(), localVisibilityChecker1); _addDeserializerConstructors(paramDeserializationConfig, paramBasicBeanDescription, localVisibilityChecker2, localAnnotationIntrospector, localCreatorContainer); _addDeserializerFactoryMethods(paramDeserializationConfig, paramBasicBeanDescription, localVisibilityChecker2, localAnnotationIntrospector, localCreatorContainer); return localCreatorContainer; }
public static EnumValues constructFromName(Class<Enum<?>> paramClass, AnnotationIntrospector paramAnnotationIntrospector) { Enum[] arrayOfEnum = (Enum[])ClassUtil.findEnumType(paramClass).getEnumConstants(); if (arrayOfEnum != null) { HashMap localHashMap = new HashMap(); int i = arrayOfEnum.length; for (int j = 0; j < i; j++) { Enum localEnum = arrayOfEnum[j]; localHashMap.put(localEnum, new SerializedString(paramAnnotationIntrospector.findEnumValue(localEnum))); } return new EnumValues(localHashMap); } throw new IllegalArgumentException("Can not determine enum constants for Class " + paramClass.getName()); }
public static EnumValues constructFromToString(Class<Enum<?>> paramClass, AnnotationIntrospector paramAnnotationIntrospector) { Enum[] arrayOfEnum = (Enum[])ClassUtil.findEnumType(paramClass).getEnumConstants(); if (arrayOfEnum != null) { HashMap localHashMap = new HashMap(); int i = arrayOfEnum.length; for (int j = 0; j < i; j++) { Enum localEnum = arrayOfEnum[j]; localHashMap.put(localEnum, new SerializedString(localEnum.toString())); } return new EnumValues(localHashMap); } throw new IllegalArgumentException("Can not determine enum constants for Class " + paramClass.getName()); }
@Bean(name="defaultObjectMapper") public ObjectMapper getObjectMapper() { if(defaultObjectMapper==null) { ObjectMapper mapper = new ObjectMapper(); AnnotationIntrospector primary = new JaxbAnnotationIntrospector(); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); mapper.getDeserializationConfig().setAnnotationIntrospector(pair); mapper.getDeserializationConfig().set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true); this.defaultObjectMapper = mapper; } return defaultObjectMapper; }
public BasicBeanDescription forSerialization(SerializationConfig cfg, Class<?> c, MixInResolver r) { AnnotationIntrospector ai = cfg.getAnnotationIntrospector(); AnnotatedClass ac = AnnotatedClass.construct(c, ai, r); // False -> no need to collect ignorable member list ac.resolveMemberMethods(getSerializationMethodFilter(cfg), false); /* only the default constructor needed here (that's needed * in case we need to check default bean property values, * to omit them) */ /* 31-Oct-2009, tatus: Actually, creator info will come in handy * for resolving [JACKSON-170] as well */ ac.resolveCreators(true); // False -> no need to collect ignorable field list ac.resolveFields(false); return new BasicBeanDescription(TypeFactory.type(c), ac, ai); }
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass paramAnnotatedClass, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector) { HashMap localHashMap = new HashMap(); if (this._registeredSubtypes != null) { Class localClass = paramAnnotatedClass.getRawType(); Iterator localIterator = this._registeredSubtypes.iterator(); while (localIterator.hasNext()) { NamedType localNamedType = (NamedType)localIterator.next(); if (localClass.isAssignableFrom(localNamedType.getType())) _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType, paramMapperConfig, paramAnnotationIntrospector, localHashMap); } } _collectAndResolve(paramAnnotatedClass, new NamedType(paramAnnotatedClass.getRawType(), null), paramMapperConfig, paramAnnotationIntrospector, localHashMap); return new ArrayList(localHashMap.values()); }
protected POJOPropertiesCollector(MapperConfig<?> paramMapperConfig, boolean paramBoolean, JavaType paramJavaType, AnnotatedClass paramAnnotatedClass) { this._config = paramMapperConfig; this._forSerialization = paramBoolean; this._type = paramJavaType; this._classDef = paramAnnotatedClass; boolean bool = paramMapperConfig.isAnnotationProcessingEnabled(); AnnotationIntrospector localAnnotationIntrospector = null; if (bool) localAnnotationIntrospector = this._config.getAnnotationIntrospector(); this._annotationIntrospector = localAnnotationIntrospector; if (this._annotationIntrospector == null) { this._visibilityChecker = this._config.getDefaultVisibilityChecker(); return; } this._visibilityChecker = this._annotationIntrospector.findAutoDetectVisibility(paramAnnotatedClass, this._config.getDefaultVisibilityChecker()); }
protected void _addInjectables() { AnnotationIntrospector localAnnotationIntrospector = this._annotationIntrospector; if (localAnnotationIntrospector == null); while (true) { return; Iterator localIterator1 = this._classDef.fields().iterator(); while (localIterator1.hasNext()) { AnnotatedField localAnnotatedField = (AnnotatedField)localIterator1.next(); _doAddInjectable(localAnnotationIntrospector.findInjectableValueId(localAnnotatedField), localAnnotatedField); } Iterator localIterator2 = this._classDef.memberMethods().iterator(); while (localIterator2.hasNext()) { AnnotatedMethod localAnnotatedMethod = (AnnotatedMethod)localIterator2.next(); if (localAnnotatedMethod.getParameterCount() == 1) _doAddInjectable(localAnnotationIntrospector.findInjectableValueId(localAnnotatedMethod), localAnnotatedMethod); } } }
protected ValueInstantiator constructDefaultValueInstantiator(DeserializationConfig paramDeserializationConfig, BasicBeanDescription paramBasicBeanDescription) { boolean bool = paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS); CreatorCollector localCreatorCollector = new CreatorCollector(paramBasicBeanDescription, bool); AnnotationIntrospector localAnnotationIntrospector = paramDeserializationConfig.getAnnotationIntrospector(); if (paramBasicBeanDescription.getType().isConcrete()) { AnnotatedConstructor localAnnotatedConstructor = paramBasicBeanDescription.findDefaultConstructor(); if (localAnnotatedConstructor != null) { if (bool) ClassUtil.checkAndFixAccess(localAnnotatedConstructor.getAnnotated()); localCreatorCollector.setDefaultConstructor(localAnnotatedConstructor); } } VisibilityChecker localVisibilityChecker1 = paramDeserializationConfig.getDefaultVisibilityChecker(); VisibilityChecker localVisibilityChecker2 = paramDeserializationConfig.getAnnotationIntrospector().findAutoDetectVisibility(paramBasicBeanDescription.getClassInfo(), localVisibilityChecker1); _addDeserializerFactoryMethods(paramDeserializationConfig, paramBasicBeanDescription, localVisibilityChecker2, localAnnotationIntrospector, localCreatorCollector); _addDeserializerConstructors(paramDeserializationConfig, paramBasicBeanDescription, localVisibilityChecker2, localAnnotationIntrospector, localCreatorCollector); return localCreatorCollector.constructValueInstantiator(paramDeserializationConfig); }
protected SettableBeanProperty constructSettableProperty(DeserializationConfig paramDeserializationConfig, BasicBeanDescription paramBasicBeanDescription, String paramString, AnnotatedField paramAnnotatedField) { if (paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) paramAnnotatedField.fixAccess(); JavaType localJavaType1 = paramBasicBeanDescription.bindingsForBeanType().resolveType(paramAnnotatedField.getGenericType()); BeanProperty.Std localStd = new BeanProperty.Std(paramString, localJavaType1, paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedField); JavaType localJavaType2 = resolveType(paramDeserializationConfig, paramBasicBeanDescription, localJavaType1, paramAnnotatedField, localStd); if (localJavaType2 != localJavaType1) localStd = localStd.withType(localJavaType2); JsonDeserializer localJsonDeserializer = findDeserializerFromAnnotation(paramDeserializationConfig, paramAnnotatedField, localStd); JavaType localJavaType3 = modifyTypeByAnnotation(paramDeserializationConfig, paramAnnotatedField, localJavaType2, paramString); Object localObject = new SettableBeanProperty.FieldProperty(paramString, localJavaType3, (TypeDeserializer)localJavaType3.getTypeHandler(), paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedField); if (localJsonDeserializer != null) localObject = ((SettableBeanProperty)localObject).withValueDeserializer(localJsonDeserializer); AnnotationIntrospector.ReferenceProperty localReferenceProperty = paramDeserializationConfig.getAnnotationIntrospector().findReferenceType(paramAnnotatedField); if ((localReferenceProperty != null) && (localReferenceProperty.isManagedReference())) ((SettableBeanProperty)localObject).setManagedReferenceName(localReferenceProperty.getName()); return localObject; }
protected SettableBeanProperty constructSettableProperty(DeserializationConfig paramDeserializationConfig, BasicBeanDescription paramBasicBeanDescription, String paramString, AnnotatedMethod paramAnnotatedMethod) { if (paramDeserializationConfig.isEnabled(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS)) paramAnnotatedMethod.fixAccess(); JavaType localJavaType1 = paramBasicBeanDescription.bindingsForBeanType().resolveType(paramAnnotatedMethod.getParameterType(0)); BeanProperty.Std localStd = new BeanProperty.Std(paramString, localJavaType1, paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedMethod); JavaType localJavaType2 = resolveType(paramDeserializationConfig, paramBasicBeanDescription, localJavaType1, paramAnnotatedMethod, localStd); if (localJavaType2 != localJavaType1) localStd = localStd.withType(localJavaType2); JsonDeserializer localJsonDeserializer = findDeserializerFromAnnotation(paramDeserializationConfig, paramAnnotatedMethod, localStd); JavaType localJavaType3 = modifyTypeByAnnotation(paramDeserializationConfig, paramAnnotatedMethod, localJavaType2, paramString); Object localObject = new SettableBeanProperty.MethodProperty(paramString, localJavaType3, (TypeDeserializer)localJavaType3.getTypeHandler(), paramBasicBeanDescription.getClassAnnotations(), paramAnnotatedMethod); if (localJsonDeserializer != null) localObject = ((SettableBeanProperty)localObject).withValueDeserializer(localJsonDeserializer); AnnotationIntrospector.ReferenceProperty localReferenceProperty = paramDeserializationConfig.getAnnotationIntrospector().findReferenceType(paramAnnotatedMethod); if ((localReferenceProperty != null) && (localReferenceProperty.isManagedReference())) ((SettableBeanProperty)localObject).setManagedReferenceName(localReferenceProperty.getName()); return localObject; }
public JsonModelDeserializer(Class<T> deserializedObjectType) { super(); this.deserializedObjectType = deserializedObjectType; objectMapper = new ObjectMapper(); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make serializer use JAXB annotations (only) objectMapper.setDeserializationConfig(objectMapper.getDeserializationConfig().withAnnotationIntrospector(introspector)); objectTypeXmlTagName = deserializedObjectType.getAnnotation(XmlRootElement.class).name(); }
/** * Update the generator with a default codec and pretty printer * * @param jsonFactory Factory to set as codec * @param jsonGenerator Generator to configure */ private static void updateGenerator(JsonFactory jsonFactory, JsonGenerator jsonGenerator) { ObjectMapper mapper = new ObjectMapper(jsonFactory); //Update the annotation interceptor to also include jaxb annotations as a second choice AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector() { /** * BUG FIX: * By contract, if findSerializationInclusion didn't encounter any annotations that should change the * inclusion value, it should return the default value it has received; but actually returns null, which * overrides the NON_NULL option we set. * The doc states issue JACKSON-256 which was supposed to be fixed in 1.5.0. *twilight zone theme song* */ @Override public JsonSerialize.Inclusion findSerializationInclusion(Annotated a, JsonSerialize.Inclusion defValue) { JsonSerialize.Inclusion inclusion = super.findSerializationInclusion(a, defValue); if (inclusion == null) { return defValue; } return inclusion; } }; AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); jsonGenerator.setCodec(mapper); jsonGenerator.useDefaultPrettyPrinter(); }
/** * Update the parser with a default codec * * @param jsonFactory Factory to set as codec * @param jsonParser Parser to configure */ private static void updateParser(JsonFactory jsonFactory, JsonParser jsonParser) { AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); ObjectMapper mapper = new ObjectMapper(jsonFactory); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getDeserializationConfig().setAnnotationIntrospector(pair); mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES); jsonParser.setCodec(mapper); }
public JsonProvider() { ObjectMapper mapper = getMapper(); //Update the annotation interceptor to also include jaxb annotations as a second choice AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); mapper.getSerializationConfig().setAnnotationIntrospector(pair); mapper.getSerializationConfig().setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL); mapper.getDeserializationConfig().setAnnotationIntrospector(pair); //Ignore missing properties mapper.getDeserializationConfig().disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES); }
public JacksonJaxbContextResolver() { this.objectMapper = new ObjectMapper(); final AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); final AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); final AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); this.objectMapper.getDeserializationConfig().setAnnotationIntrospector(pair); this.objectMapper.getSerializationConfig().setAnnotationIntrospector(pair); }
public ObjectMapperFactoryBean() { this.objectMapper = new ObjectMapper(); this.objectMapper.setSerializationInclusion(Inclusion.NON_NULL); this.objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); AnnotationIntrospector primary = new JacksonAnnotationIntrospector(); AnnotationIntrospector secondary = new JaxbAnnotationIntrospector(); AnnotationIntrospector pair = new AnnotationIntrospector.Pair(primary, secondary); this.objectMapper.setAnnotationIntrospector(pair); }
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedMember paramAnnotatedMember, MapperConfig<?> paramMapperConfig, AnnotationIntrospector paramAnnotationIntrospector) { HashMap localHashMap = new HashMap(); if (this._registeredSubtypes != null) { Class localClass = paramAnnotatedMember.getRawType(); Iterator localIterator2 = this._registeredSubtypes.iterator(); while (localIterator2.hasNext()) { NamedType localNamedType3 = (NamedType)localIterator2.next(); if (!localClass.isAssignableFrom(localNamedType3.getType())) continue; _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType3.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType3, paramMapperConfig, paramAnnotationIntrospector, localHashMap); } } List localList = paramAnnotationIntrospector.findSubtypes(paramAnnotatedMember); if (localList != null) { Iterator localIterator1 = localList.iterator(); while (localIterator1.hasNext()) { NamedType localNamedType2 = (NamedType)localIterator1.next(); _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(localNamedType2.getType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType2, paramMapperConfig, paramAnnotationIntrospector, localHashMap); } } NamedType localNamedType1 = new NamedType(paramAnnotatedMember.getRawType(), null); _collectAndResolve(AnnotatedClass.constructWithoutSuperTypes(paramAnnotatedMember.getRawType(), paramAnnotationIntrospector, paramMapperConfig), localNamedType1, paramMapperConfig, paramAnnotationIntrospector, localHashMap); return new ArrayList(localHashMap.values()); }
public TypeSerializer findPropertyContentTypeSerializer(JavaType paramJavaType, SerializationConfig paramSerializationConfig, AnnotatedMember paramAnnotatedMember, BeanProperty paramBeanProperty) throws JsonMappingException { JavaType localJavaType = paramJavaType.getContentType(); AnnotationIntrospector localAnnotationIntrospector = paramSerializationConfig.getAnnotationIntrospector(); TypeResolverBuilder localTypeResolverBuilder = localAnnotationIntrospector.findPropertyContentTypeResolver(paramSerializationConfig, paramAnnotatedMember, paramJavaType); if (localTypeResolverBuilder == null) return createTypeSerializer(paramSerializationConfig, localJavaType, paramBeanProperty); return localTypeResolverBuilder.buildTypeSerializer(paramSerializationConfig, localJavaType, paramSerializationConfig.getSubtypeResolver().collectAndResolveSubtypes(paramAnnotatedMember, paramSerializationConfig, localAnnotationIntrospector), paramBeanProperty); }