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

Commit 60f0ff2

Browse files
committed
Try to resolve #27
1 parent cae2916 commit 60f0ff2

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

release-notes/VERSION

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
Project: jackson-module-jaxb-annotations
2-
Version: 2.3.2 (01-Mar-2014)
2+
Version: 2.3.3 (xx-xxx-2014)
33

4-
No functional changes.
4+
#27: Try to make `JaxbAnnotationIntrospector` work with Jackson XML module
5+
in determining whether property is output as attribute
6+
(reported by jbuhacoff@github)
57

68
------------------------------------------------------------------------
79
=== History: ===
810
------------------------------------------------------------------------
911

12+
2.3.2 (01-Mar-2014)
1013
2.3.1 (28-Dec-2013)
1114

1215
No functional changes.

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

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.fasterxml.jackson.databind.util.BeanUtil;
2727
import com.fasterxml.jackson.databind.util.ClassUtil;
2828
import com.fasterxml.jackson.databind.util.Converter;
29-
3029
import com.fasterxml.jackson.module.jaxb.deser.DataHandlerJsonDeserializer;
3130
import com.fasterxml.jackson.module.jaxb.ser.DataHandlerJsonSerializer;
3231

@@ -60,6 +59,13 @@
6059
* <li>Any property annotated with {@link XmlValue} will have a property named 'value' on its JSON object.
6160
* </li>
6261
* </ul>
62+
*
63+
*
64+
*<p>
65+
* A note on compatibility with Jackson XML module: since this module does not depend
66+
* on Jackson XML module, it is bit difficult to make sure we will properly expose
67+
* all information. But effort is made (as of version 2.3.3) to expose this information,
68+
* even without using a specific sub-class from that project.
6369
*
6470
* @author Ryan Heaton
6571
* @author Tatu Saloranta
@@ -134,6 +140,67 @@ public Version version() {
134140
return PackageVersion.VERSION;
135141
}
136142

143+
/*
144+
/**********************************************************
145+
/* Extended API (XmlAnnotationIntrospector)
146+
/**********************************************************
147+
*/
148+
149+
// From XmlAnnotationIntrospector
150+
// @Override
151+
public String findNamespace(Annotated ann) {
152+
String ns = null;
153+
if (ann instanceof AnnotatedClass) {
154+
// For classes, it must be @XmlRootElement. Also, we do
155+
// want to use defaults from package, base class
156+
XmlRootElement elem = findRootElementAnnotation((AnnotatedClass) ann);
157+
if (elem != null) {
158+
ns = elem.namespace();
159+
}
160+
} else {
161+
// For others, XmlElement or XmlAttribute work (anything else?)
162+
XmlElement elem = findAnnotation(XmlElement.class, ann, false, false, false);
163+
if (elem != null) {
164+
ns = elem.namespace();
165+
}
166+
if (ns == null || MARKER_FOR_DEFAULT.equals(ns)) {
167+
XmlAttribute attr = findAnnotation(XmlAttribute.class, ann, false, false, false);
168+
if (attr != null) {
169+
ns = attr.namespace();
170+
}
171+
}
172+
}
173+
// JAXB uses marker for "not defined"
174+
if (MARKER_FOR_DEFAULT.equals(ns)) {
175+
ns = null;
176+
}
177+
return ns;
178+
}
179+
180+
// From XmlAnnotationIntrospector
181+
// @Override
182+
public Boolean isOutputAsAttribute(Annotated ann) {
183+
XmlAttribute attr = findAnnotation(XmlAttribute.class, ann, false, false, false);
184+
if (attr != null) {
185+
return Boolean.TRUE;
186+
}
187+
XmlElement elem = findAnnotation(XmlElement.class, ann, false, false, false);
188+
if (elem != null) {
189+
return Boolean.FALSE;
190+
}
191+
return null;
192+
}
193+
194+
// From XmlAnnotationIntrospector
195+
// @Override
196+
public Boolean isOutputAsText(Annotated ann) {
197+
XmlValue attr = findAnnotation(XmlValue.class, ann, false, false, false);
198+
if (attr != null) {
199+
return Boolean.TRUE;
200+
}
201+
return null;
202+
}
203+
137204
/*
138205
/**********************************************************
139206
/* General annotations (for classes, properties)

0 commit comments

Comments
 (0)