Skip to content

Commit 167005f

Browse files
committed
1 parent cc4c444 commit 167005f

File tree

5 files changed

+62
-6
lines changed

5 files changed

+62
-6
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* this may become partially supported as per [JACKSON-253].
3939
* <li>{@link javax.xml.bind.annotation.XmlInlineBinaryData} since the underlying concepts
4040
* (like XOP) do not exist in JSON -- Jackson will always use inline base64 encoding as the method
41-
* <li>{@link javax.xml.bind.annotation.XmlList} because JSON does have (or necessarily need)
41+
* <li>{@link javax.xml.bind.annotation.XmlList} because JSON does not have (or necessarily need)
4242
* method of serializing list of values as space-separated Strings
4343
* <li>{@link javax.xml.bind.annotation.XmlMimeType}
4444
* <li>{@link javax.xml.bind.annotation.XmlMixed} since JSON has no concept of mixed content
@@ -1352,6 +1352,8 @@ private PropertyName findJaxbPropertyName(Annotated ae, Class<?> aeType, String
13521352
}
13531353
if (!hasAName) {
13541354
hasAName = ae.hasAnnotation(XmlElementWrapper.class)
1355+
// [modules-base#44]: should consider this as implicit marker
1356+
|| ae.hasAnnotation(XmlElements.class)
13551357
// 09-Aug-2014, tatu: Note: prior to 2.4.2, we used to give explicit name "value"
13561358
// if there was "@XmlValue" annotation; since then, only implicit name.
13571359
|| ae.hasAnnotation(XmlValue.class);

jaxb/src/test/java/com/fasterxml/jackson/module/jaxb/introspect/TestPropertyVisibility.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import javax.xml.bind.annotation.*;
66

7+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
78
import com.fasterxml.jackson.databind.*;
89

910
import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
@@ -47,19 +48,45 @@ public void setRawType(int type) {
4748
}
4849
}
4950

51+
// for [modules-base#44]
52+
static class Foo44 {
53+
public String foo = "bar";
54+
}
55+
56+
@XmlAccessorType(XmlAccessType.NONE)
57+
@JsonPropertyOrder({ "object", "other" })
58+
static class NoneAccessBean
59+
{
60+
@XmlElements({
61+
@XmlElement(type=Foo44.class, name="foo")
62+
})
63+
public Object object;
64+
65+
@XmlElement
66+
public Object other;
67+
68+
public NoneAccessBean() { }
69+
public NoneAccessBean(Object o) { object = o; }
70+
public NoneAccessBean(Object o, Object b) {
71+
object = o;
72+
other = b;
73+
}
74+
}
75+
5076
/*
5177
/**********************************************************
5278
/* Unit tests
5379
/**********************************************************
5480
*/
5581

82+
private final ObjectMapper MAPPER = getJaxbMapper();
83+
5684
// Verify serialization wrt [JACKSON-354]
5785
//
5886
// NOTE: fails currently because we use Bean Introspector which only sees public methods -- need to rewrite
5987
public void testJackson354Serialization() throws IOException
6088
{
61-
ObjectMapper mapper = getJaxbMapper();
62-
assertEquals("{\"name\":\"foo\"}", mapper.writeValueAsString(new Bean354()));
89+
assertEquals("{\"name\":\"foo\"}", MAPPER.writeValueAsString(new Bean354()));
6390
}
6491

6592
// For [JACKSON-539]
@@ -76,10 +103,17 @@ public void testJacksonSerialization()
76103

77104
Jackson539Bean input = new Jackson539Bean();
78105
input.type = 123;
79-
ObjectMapper mapper = getJaxbMapper();
80-
String json = mapper.writeValueAsString(input);
81-
Jackson539Bean result = mapper.readValue(json, Jackson539Bean.class);
106+
String json = MAPPER.writeValueAsString(input);
107+
Jackson539Bean result = MAPPER.readValue(json, Jackson539Bean.class);
82108
assertNotNull(result);
83109
assertEquals(123, result.type);
84110
}
111+
112+
// for [modules-base#44]
113+
public void testNoneAccessWithXmlElements() throws Exception
114+
{
115+
NoneAccessBean input = new NoneAccessBean(new Foo44());
116+
assertEquals(aposToQuotes("{'object':{'foo':{'foo':'bar'}},'other':null}"),
117+
MAPPER.writeValueAsString(input));
118+
}
85119
}

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ not datatype, data format, or JAX-RS provider modules.
4747
</dependency>
4848
</dependencies>
4949

50+
51+
<!-- Alas, need to include snapshot reference since otherwise can not find
52+
snapshot of parent... -->
53+
<repositories>
54+
<repository>
55+
<id>sonatype-nexus-snapshots</id>
56+
<name>Sonatype Nexus Snapshots</name>
57+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
58+
<releases><enabled>false</enabled></releases>
59+
<snapshots><enabled>true</enabled></snapshots>
60+
</repository>
61+
</repositories>
62+
5063
<build>
5164
<pluginManagement>
5265
<plugins>

release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ Tuomas Kiviaho (TuomasKiviaho@github)
1414

1515
* Reported #42: NPE from MrBean when `get()` or `set()` is though as property
1616
(2.9.5)
17+
18+
Alexander Onnikov (aonnikov@github)
19+
20+
* Reported #44: (jaxb) `@XmlElements` does not work with `@XmlAccessorType(XmlAccessType.NONE)`
21+
(2.9.6)

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Modules:
1212

1313
2.9.6 (not yet released)
1414

15+
#44: (jaxb) `@XmlElements` does not work with `@XmlAccessorType(XmlAccessType.NONE)`
16+
(reported by Alexander O)
1517
- (afterburner) Cleaning up issues wrt null-skipping/handling (wrt `@JsonSetter(nulls)`
1618

1719
2.9.5 (26-Mar-2018)

0 commit comments

Comments
 (0)