AnnotationIntrospector primary = new ExtendedJaxbAnnotationIntrospector(customClasses, customSerializationMapper); AnnotationIntrospector secondary = new JacksonAnnotationIntrospector(); AnnotationIntrospector introspectorPair = AnnotationIntrospector.pair(primary, secondary);
@Override public JsonSerializer<?> findSerializer(Annotated am) { // replace JaxbUnknownAdapter as it breaks JSON marshaller for list and maps with wrapping serializer XmlJavaTypeAdapter adapterInfo = findAnnotation(XmlJavaTypeAdapter.class, am, true, false, false); if (adapterInfo != null && adapterInfo.value().isAssignableFrom(JaxbUnknownAdapter.class)) { if ( findAnnotation(JsonSerialize.class, am, true, false, false) != null ) { // .. unless there is also an explicitly specified serializer, in such case use the specified one: return super.findSerializer(am); } return new WrappingObjectSerializer(customObjectMapper); } return super.findSerializer(am); }
private XmlAdapter<Object,Object> findAdapter(Annotated am, boolean forSerialization, Class<?> type) { // First of all, are we looking for annotations for class? if (am instanceof AnnotatedClass) { return findAdapterForClass((AnnotatedClass) am, forSerialization); } // Otherwise for a member. First, let's figure out type of property XmlJavaTypeAdapter adapterInfo = findAnnotation(XmlJavaTypeAdapter.class, am, true, false, false); if (adapterInfo != null) { XmlAdapter<Object,Object> adapter = checkAdapter(adapterInfo, type, forSerialization); if (adapter != null) { return adapter; } } XmlJavaTypeAdapters adapters = findAnnotation(XmlJavaTypeAdapters.class, am, true, false, false); if (adapters != null) { for (XmlJavaTypeAdapter info : adapters.value()) { XmlAdapter<Object,Object> adapter = checkAdapter(info, type, forSerialization); if (adapter != null) { return adapter; } } } return null; }
@Override public Object findSerializationConverter(Annotated a) { Class<?> serType = _rawSerializationType(a); // Can apply to both container and regular type; no difference yet here XmlAdapter<?,?> adapter = findAdapter(a, true, serType); if (adapter != null) { return _converter(adapter, true); } return null; }