Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit acf8695

Browse files
committed
Work on #27
1 parent 436ade6 commit acf8695

File tree

1 file changed

+68
-3
lines changed

1 file changed

+68
-3
lines changed

src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
import com.fasterxml.jackson.annotation.JsonTypeInfo;
1515
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
1616
import com.fasterxml.jackson.annotation.SimpleObjectIdResolver;
17-
1817
import com.fasterxml.jackson.core.*;
19-
2018
import com.fasterxml.jackson.databind.*;
2119
import com.fasterxml.jackson.databind.cfg.MapperConfig;
2220
import com.fasterxml.jackson.databind.introspect.*;
@@ -27,7 +25,6 @@
2725
import com.fasterxml.jackson.databind.util.BeanUtil;
2826
import com.fasterxml.jackson.databind.util.ClassUtil;
2927
import com.fasterxml.jackson.databind.util.Converter;
30-
3128
import com.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer;
3229
import com.fasterxml.jackson.module.jaxb.ser.DataHandlerJsonSerializer;
3330

@@ -61,6 +58,13 @@
6158
* <li>Any property annotated with {@link XmlValue} will have a property named 'value' on its JSON object.
6259
* </li>
6360
* </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.
6468
*
6569
* @author Ryan Heaton
6670
* @author Tatu Saloranta
@@ -135,6 +139,67 @@ public Version version() {
135139
return PackageVersion.VERSION;
136140
}
137141

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+
138203
/*
139204
/**********************************************************
140205
/* General annotations (for classes, properties)

0 commit comments

Comments
 (0)