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(); } } }
@Override public Object findFilterId(Annotated a) { if (Map.class.isAssignableFrom(a.getRawType())) { return filterName; } return super.findFilterId(a); } });
@Override public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config, AnnotatedClass ac, JavaType baseType) { return _findTypeResolver(config, ac, baseType); }
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class); JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class); b = config.typeResolverBuilderInstance(ann, resAnn.value()); } else { // if not, use standard one, if indicated by annotations if (info == null) { return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder(); JsonTypeIdResolver idResInfo = _findAnnotation(ann, JsonTypeIdResolver.class); TypeIdResolver idRes = (idResInfo == null) ? null : config.typeIdResolverInstance(ann, idResInfo.value()); if (idRes != null) { idRes.init(baseType);
new JacksonAnnotationIntrospector(), null) .getAnnotation(JsonIgnoreProperties.class); List<String> jsonIgnoreProperties = jsonIgnorePropertiesAnnotation == null ? null .getAnnotation(JsonProperty.class); String propertyName = jsonProperty != null && !StringUtils.isNullOrEmpty(jsonProperty.value()) ? jsonProperty .value() : pd.getName(); .value() : ""); property.setType(propertyTypeInfo.getRepresentationName()); property.setRequired(jsonProperty != null && jsonProperty.required()); property.setList(propertyTypeInfo.isList());
mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() { @Override public PropertyName findNameForDeserialization(Annotated a) { return new PropertyName(path.split("\\.")[0]);
@Override public boolean hasIgnoreMarker(AnnotatedMember m) { return _isIgnorable(m); }
.getRepresentationClazz()); JsonIgnoreProperties jsonIgnorePropertiesAnnotation = AnnotatedClass.construct(typeInfo.getRepresentationClazz(), new JacksonAnnotationIntrospector(), null).getAnnotation(JsonIgnoreProperties.class); List<String> jsonIgnoreProperties = jsonIgnorePropertiesAnnotation == null ? null : Arrays.asList(jsonIgnorePropertiesAnnotation.value()); String propertyName = jsonProperty != null && !StringUtils.isNullOrEmpty(jsonProperty.value()) ? jsonProperty.value() : pd.getName(); property.setDescription(jsonPropertyDescription != null ? jsonPropertyDescription.value() : ""); property.setType(propertyTypeInfo.getRepresentationName()); property.setRequired(jsonProperty != null && jsonProperty.required()); property.setList(propertyTypeInfo.isList());
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class); JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class); b = config.typeResolverBuilderInstance(ann, resAnn.value()); } else { // if not, use standard one, if indicated by annotations if (info == null) { return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder(); JsonTypeIdResolver idResInfo = _findAnnotation(ann, JsonTypeIdResolver.class); TypeIdResolver idRes = (idResInfo == null) ? null : config.typeIdResolverInstance(ann, idResInfo.value()); if (idRes != null) { // [JACKSON-359] idRes.init(baseType);
@Override public boolean hasIgnoreMarker(AnnotatedMember m) { return _isIgnorable(m); }
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() { final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()); final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector(); return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector); } }
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class); JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class); b = config.typeResolverBuilderInstance(ann, resAnn.value()); } else { // if not, use standard one, if indicated by annotations if (info == null) { return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder(); JsonTypeIdResolver idResInfo = _findAnnotation(ann, JsonTypeIdResolver.class); TypeIdResolver idRes = (idResInfo == null) ? null : config.typeIdResolverInstance(ann, idResInfo.value()); if (idRes != null) { idRes.init(baseType);
@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.getContentType() == null) { throw new IllegalArgumentException("Must call method with a container or reference type (got "+containerType+")"); } return _findTypeResolver(config, am, containerType); }
@Override public Object findFilterId(final Annotated a) { final Object filterId = super.findFilterId(a); if (filterId != null) { return filterId; } if (a instanceof AnnotatedMethod) { final Method method = ((AnnotatedMethod) a).getAnnotated(); // Interested only in getters - trying to obtain "field" name from them. if (ReflectionHelper.isGetter(method)) { return ReflectionHelper.getPropertyName(method); } } if (a instanceof AnnotatedField || a instanceof AnnotatedClass) { return a.getName(); } return null; } }));
@Override public boolean hasIgnoreMarker(AnnotatedMember m) { return _isIgnorable(m); }
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; } }
JsonTypeInfo info = _findAnnotation(ann, JsonTypeInfo.class); JsonTypeResolver resAnn = _findAnnotation(ann, JsonTypeResolver.class); b = config.typeResolverBuilderInstance(ann, resAnn.value()); } else { // if not, use standard one, if indicated by annotations if (info == null) { return _constructNoTypeResolverBuilder(); b = _constructStdTypeResolverBuilder(); JsonTypeIdResolver idResInfo = _findAnnotation(ann, JsonTypeIdResolver.class); TypeIdResolver idRes = (idResInfo == null) ? null : config.typeIdResolverInstance(ann, idResInfo.value()); if (idRes != null) { idRes.init(baseType);
@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: */ // 17-Apr-2016, tatu: For 2.7.4 make sure ReferenceType also included if (baseType.isContainerType() || baseType.isReferenceType()) { return null; } // No per-member type overrides (yet) return _findTypeResolver(config, am, baseType); }
@Override public Object findFilterId(Annotated a) { Object id = super.findFilterId(a); if (id == null) { id = CONFIGURATION_PROPERTIES_FILTER_ID; } return id; }
@Override public boolean hasIgnoreMarker(AnnotatedMember m) { return _isIgnorable(m); }