|
14 | 14 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
15 | 15 | import com.fasterxml.jackson.annotation.ObjectIdGenerators;
|
16 | 16 | import com.fasterxml.jackson.annotation.SimpleObjectIdResolver;
|
17 |
| - |
18 | 17 | import com.fasterxml.jackson.core.*;
|
19 |
| - |
20 | 18 | import com.fasterxml.jackson.databind.*;
|
21 | 19 | import com.fasterxml.jackson.databind.cfg.MapperConfig;
|
22 | 20 | import com.fasterxml.jackson.databind.introspect.*;
|
|
27 | 25 | import com.fasterxml.jackson.databind.util.BeanUtil;
|
28 | 26 | import com.fasterxml.jackson.databind.util.ClassUtil;
|
29 | 27 | import com.fasterxml.jackson.databind.util.Converter;
|
30 |
| - |
31 | 28 | import com.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer;
|
32 | 29 | import com.fasterxml.jackson.module.jaxb.ser.DataHandlerJsonSerializer;
|
33 | 30 |
|
|
61 | 58 | * <li>Any property annotated with {@link XmlValue} will have a property named 'value' on its JSON object.
|
62 | 59 | * </li>
|
63 | 60 | * </ul>
|
| 61 | + * |
| 62 | + * |
| 63 | + *<p> |
| 64 | + * A note on compatibility with Jackson XML module: since this module does not depend |
| 65 | + * on Jackson XML module, it is bit difficult to make sure we will properly expose |
| 66 | + * all information. But effort is made (as of version 2.3.3) to expose this information, |
| 67 | + * even without using a specific sub-class from that project. |
64 | 68 | *
|
65 | 69 | * @author Ryan Heaton
|
66 | 70 | * @author Tatu Saloranta
|
@@ -135,6 +139,67 @@ public Version version() {
|
135 | 139 | return PackageVersion.VERSION;
|
136 | 140 | }
|
137 | 141 |
|
| 142 | + /* |
| 143 | + /********************************************************** |
| 144 | + /* Extended API (XmlAnnotationIntrospector) |
| 145 | + /********************************************************** |
| 146 | + */ |
| 147 | + |
| 148 | + // From XmlAnnotationIntrospector |
| 149 | + // @Override |
| 150 | + public String findNamespace(Annotated ann) { |
| 151 | + String ns = null; |
| 152 | + if (ann instanceof AnnotatedClass) { |
| 153 | + // For classes, it must be @XmlRootElement. Also, we do |
| 154 | + // want to use defaults from package, base class |
| 155 | + XmlRootElement elem = findRootElementAnnotation((AnnotatedClass) ann); |
| 156 | + if (elem != null) { |
| 157 | + ns = elem.namespace(); |
| 158 | + } |
| 159 | + } else { |
| 160 | + // For others, XmlElement or XmlAttribute work (anything else?) |
| 161 | + XmlElement elem = findAnnotation(XmlElement.class, ann, false, false, false); |
| 162 | + if (elem != null) { |
| 163 | + ns = elem.namespace(); |
| 164 | + } |
| 165 | + if (ns == null || MARKER_FOR_DEFAULT.equals(ns)) { |
| 166 | + XmlAttribute attr = findAnnotation(XmlAttribute.class, ann, false, false, false); |
| 167 | + if (attr != null) { |
| 168 | + ns = attr.namespace(); |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + // JAXB uses marker for "not defined" |
| 173 | + if (MARKER_FOR_DEFAULT.equals(ns)) { |
| 174 | + ns = null; |
| 175 | + } |
| 176 | + return ns; |
| 177 | + } |
| 178 | + |
| 179 | + // From XmlAnnotationIntrospector |
| 180 | + // @Override |
| 181 | + public Boolean isOutputAsAttribute(Annotated ann) { |
| 182 | + XmlAttribute attr = findAnnotation(XmlAttribute.class, ann, false, false, false); |
| 183 | + if (attr != null) { |
| 184 | + return Boolean.TRUE; |
| 185 | + } |
| 186 | + XmlElement elem = findAnnotation(XmlElement.class, ann, false, false, false); |
| 187 | + if (elem != null) { |
| 188 | + return Boolean.FALSE; |
| 189 | + } |
| 190 | + return null; |
| 191 | + } |
| 192 | + |
| 193 | + // From XmlAnnotationIntrospector |
| 194 | + // @Override |
| 195 | + public Boolean isOutputAsText(Annotated ann) { |
| 196 | + XmlValue attr = findAnnotation(XmlValue.class, ann, false, false, false); |
| 197 | + if (attr != null) { |
| 198 | + return Boolean.TRUE; |
| 199 | + } |
| 200 | + return null; |
| 201 | + } |
| 202 | + |
138 | 203 | /*
|
139 | 204 | /**********************************************************
|
140 | 205 | /* General annotations (for classes, properties)
|
|
0 commit comments