Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 7, 2018
1 parent cc4c444 commit 167005f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* this may become partially supported as per [JACKSON-253].
* <li>{@link javax.xml.bind.annotation.XmlInlineBinaryData} since the underlying concepts
* (like XOP) do not exist in JSON -- Jackson will always use inline base64 encoding as the method
* <li>{@link javax.xml.bind.annotation.XmlList} because JSON does have (or necessarily need)
* <li>{@link javax.xml.bind.annotation.XmlList} because JSON does not have (or necessarily need)
* method of serializing list of values as space-separated Strings
* <li>{@link javax.xml.bind.annotation.XmlMimeType}
* <li>{@link javax.xml.bind.annotation.XmlMixed} since JSON has no concept of mixed content
Expand Down Expand Up @@ -1352,6 +1352,8 @@ private PropertyName findJaxbPropertyName(Annotated ae, Class<?> aeType, String
}
if (!hasAName) {
hasAName = ae.hasAnnotation(XmlElementWrapper.class)
// [modules-base#44]: should consider this as implicit marker
|| ae.hasAnnotation(XmlElements.class)
// 09-Aug-2014, tatu: Note: prior to 2.4.2, we used to give explicit name "value"
// if there was "@XmlValue" annotation; since then, only implicit name.
|| ae.hasAnnotation(XmlValue.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import javax.xml.bind.annotation.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.databind.*;

import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
Expand Down Expand Up @@ -47,19 +48,45 @@ public void setRawType(int type) {
}
}

// for [modules-base#44]
static class Foo44 {
public String foo = "bar";
}

@XmlAccessorType(XmlAccessType.NONE)
@JsonPropertyOrder({ "object", "other" })
static class NoneAccessBean
{
@XmlElements({
@XmlElement(type=Foo44.class, name="foo")
})
public Object object;

@XmlElement
public Object other;

public NoneAccessBean() { }
public NoneAccessBean(Object o) { object = o; }
public NoneAccessBean(Object o, Object b) {
object = o;
other = b;
}
}

/*
/**********************************************************
/* Unit tests
/**********************************************************
*/

private final ObjectMapper MAPPER = getJaxbMapper();

// Verify serialization wrt [JACKSON-354]
//
// NOTE: fails currently because we use Bean Introspector which only sees public methods -- need to rewrite
public void testJackson354Serialization() throws IOException
{
ObjectMapper mapper = getJaxbMapper();
assertEquals("{\"name\":\"foo\"}", mapper.writeValueAsString(new Bean354()));
assertEquals("{\"name\":\"foo\"}", MAPPER.writeValueAsString(new Bean354()));
}

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

Jackson539Bean input = new Jackson539Bean();
input.type = 123;
ObjectMapper mapper = getJaxbMapper();
String json = mapper.writeValueAsString(input);
Jackson539Bean result = mapper.readValue(json, Jackson539Bean.class);
String json = MAPPER.writeValueAsString(input);
Jackson539Bean result = MAPPER.readValue(json, Jackson539Bean.class);
assertNotNull(result);
assertEquals(123, result.type);
}

// for [modules-base#44]
public void testNoneAccessWithXmlElements() throws Exception
{
NoneAccessBean input = new NoneAccessBean(new Foo44());
assertEquals(aposToQuotes("{'object':{'foo':{'foo':'bar'}},'other':null}"),
MAPPER.writeValueAsString(input));
}
}
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ not datatype, data format, or JAX-RS provider modules.
</dependency>
</dependencies>


<!-- Alas, need to include snapshot reference since otherwise can not find
snapshot of parent... -->
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>

<build>
<pluginManagement>
<plugins>
Expand Down
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ Tuomas Kiviaho (TuomasKiviaho@github)

* Reported #42: NPE from MrBean when `get()` or `set()` is though as property
(2.9.5)

Alexander Onnikov (aonnikov@github)

* Reported #44: (jaxb) `@XmlElements` does not work with `@XmlAccessorType(XmlAccessType.NONE)`
(2.9.6)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Modules:

2.9.6 (not yet released)

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

2.9.5 (26-Mar-2018)
Expand Down

0 comments on commit 167005f

Please sign in to comment.