[Git][java-team/jackson-dataformat-xml][master] 11 commits: New upstream version 2.9.6
Markus Koschany
gitlab at salsa.debian.org
Fri Aug 17 21:29:09 BST 2018
Markus Koschany pushed to branch master at Debian Java Maintainers / jackson-dataformat-xml
Commits:
c97312dd by Markus Koschany at 2018-08-17T19:24:22Z
New upstream version 2.9.6
- - - - -
27999c1b by Markus Koschany at 2018-08-17T19:24:26Z
Update upstream source from tag 'upstream/2.9.6'
Update to upstream version '2.9.6'
with Debian dir f47107f32637691c16801c1acbe396f0585002cc
- - - - -
aa22ceb4 by Markus Koschany at 2018-08-17T19:24:42Z
Start new changelog entry.
- - - - -
98632ea3 by Markus Koschany at 2018-08-17T19:31:48Z
Add jackson-base-version.patch and use the current version of jackson-base.
- - - - -
5a20c8cc by Markus Koschany at 2018-08-17T19:35:45Z
Ignore jaxb-api dependency.
- - - - -
d33057b4 by Markus Koschany at 2018-08-17T19:47:03Z
Build-depend on libjaxb-api-java.
- - - - -
513166eb by Markus Koschany at 2018-08-17T20:12:39Z
Add javadoc-classpath.patch
- - - - -
622b7886 by Markus Koschany at 2018-08-17T20:16:17Z
Fix dh_installchangelogs override.
- - - - -
93c08ca7 by Markus Koschany at 2018-08-17T20:16:37Z
Declare compliance with Debian Policy 4.2.0.
- - - - -
62bb18cb by Markus Koschany at 2018-08-17T20:18:44Z
Update changelog
- - - - -
1572d850 by Markus Koschany at 2018-08-17T20:20:31Z
Update patch headers
- - - - -
25 changed files:
- .travis.yml
- debian/changelog
- debian/control
- + debian/patches/jackson-base-version.patch
- + debian/patches/javadoc-classpath.patch
- + debian/patches/series
- debian/rules
- pom.xml
- release-notes/CREDITS → release-notes/CREDITS-2.x
- release-notes/VERSION → release-notes/VERSION-2.x
- src/main/java/com/fasterxml/jackson/dataformat/xml/XmlMapper.java
- src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java
- src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlSerializerProvider.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/MapperCopyTest.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/VersionInfoTest.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsGenericTest.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/failing/CaseInsensitiveDeser273Test.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser294Test.java
- src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java
- + src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java
Changes:
=====================================
.travis.yml
=====================================
--- a/.travis.yml
+++ b/.travis.yml
@@ -3,8 +3,9 @@ language: java
jdk:
- openjdk7
- openjdk8
+ - oraclejdk9
branches:
only:
- master
- - "2.8"
+ - "2.9"
=====================================
debian/changelog
=====================================
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,17 @@
+jackson-dataformat-xml (2.9.6-1) unstable; urgency=medium
+
+ * New upstream version 2.9.6.
+ * Add jackson-base-version.patch and use the current version of jackson-base.
+ Unfortunately it is not possible to override a parent pom tag with
+ maven.rules.
+ * Build-depend on libjaxb-api-java.
+ * Add javadoc-classpath.patch and add the missing jaxb-api.jar to the Javadoc
+ classpath. (Closes: #906368)
+ * Fix dh_installchangelogs override. Changelog is called Version-2.x now.
+ * Declare compliance with Debian Policy 4.2.0.
+
+ -- Markus Koschany <apo at debian.org> Fri, 17 Aug 2018 22:16:58 +0200
+
jackson-dataformat-xml (2.9.4-1) unstable; urgency=medium
* New upstream version 2.9.4.
=====================================
debian/control
=====================================
--- a/debian/control
+++ b/debian/control
@@ -16,6 +16,7 @@ Build-Depends:
libjackson2-databind-java,
libjackson2-databind-java-doc,
libjackson2-module-jaxb-annotations-java,
+ libjaxb-api-java,
libmaven-bundle-plugin-java,
libmaven-enforcer-plugin-java,
libmaven-javadoc-plugin-java,
@@ -24,7 +25,7 @@ Build-Depends:
libstax2-api-java (>= 3.1.1),
maven-debian-helper (>= 1.5),
xmlstarlet
-Standards-Version: 4.1.3
+Standards-Version: 4.2.0
Vcs-Git: https://anonscm.debian.org/git/pkg-java/jackson-dataformat-xml.git
Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/jackson-dataformat-xml.git
Homepage: http://wiki.fasterxml.com/JacksonExtensionXmlDataBinding
=====================================
debian/patches/jackson-base-version.patch
=====================================
--- /dev/null
+++ b/debian/patches/jackson-base-version.patch
@@ -0,0 +1,22 @@
+From: Markus Koschany <apo at debian.org>
+Date: Fri, 17 Aug 2018 21:31:33 +0200
+Subject: jackson-base version
+
+Use the debian version.
+---
+ pom.xml | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/pom.xml b/pom.xml
+index c7ee5c5..902d87c 100644
+--- a/pom.xml
++++ b/pom.xml
+@@ -4,7 +4,7 @@
+ <parent>
+ <groupId>com.fasterxml.jackson</groupId>
+ <artifactId>jackson-base</artifactId>
+- <version>2.9.6</version>
++ <version>debian</version>
+ </parent>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-xml</artifactId>
=====================================
debian/patches/javadoc-classpath.patch
=====================================
--- /dev/null
+++ b/debian/patches/javadoc-classpath.patch
@@ -0,0 +1,36 @@
+From: Markus Koschany <apo at debian.org>
+Date: Fri, 17 Aug 2018 22:07:34 +0200
+Subject: javadoc classpath
+
+Add jaxb-api.jar to the Javadoc classpath, otherwise javadoc will fail.
+
+Bug-Debian: https://bugs.debian.org/906368
+---
+ pom.xml | 14 ++++++++++++++
+ 1 file changed, 14 insertions(+)
+
+diff --git a/pom.xml b/pom.xml
+index 902d87c..fca8726 100644
+--- a/pom.xml
++++ b/pom.xml
+@@ -116,6 +116,20 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
+ </execution>
+ </executions>
+ </plugin>
++ <plugin>
++ <groupId>org.apache.maven.plugins</groupId>
++ <artifactId>maven-javadoc-plugin</artifactId>
++ <version>3.0.1</version>
++ <configuration>
++ <additionalDependencies>
++ <additionalDependency>
++ <groupId>javax.xml.bind</groupId>
++ <artifactId>jaxb-api</artifactId>
++ <version>2.3.0</version>
++ </additionalDependency>
++ </additionalDependencies>
++ </configuration>
++ </plugin>
+ <!-- Need to skip known-failing tests for build... -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
=====================================
debian/patches/series
=====================================
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1,2 @@
+jackson-base-version.patch
+javadoc-classpath.patch
=====================================
debian/rules
=====================================
--- a/debian/rules
+++ b/debian/rules
@@ -4,7 +4,7 @@
dh $@
override_dh_installchangelogs:
- dh_installchangelogs release-notes/VERSION
+ dh_installchangelogs release-notes/VERSION-2.x
get-orig-source:
uscan --download-current-version --force-download --repack --compression xz
=====================================
pom.xml
=====================================
--- a/pom.xml
+++ b/pom.xml
@@ -4,11 +4,11 @@
<parent>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-base</artifactId>
- <version>2.9.4</version>
+ <version>2.9.6</version>
</parent>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
- <version>2.9.4</version>
+ <version>2.9.6</version>
<name>Jackson-dataformat-XML</name>
<packaging>bundle</packaging>
<description>Data format extension for Jackson (http://jackson.codehaus.org) to offer
@@ -21,7 +21,7 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
<connection>scm:git:git at github.com:FasterXML/jackson-dataformat-xml.git</connection>
<developerConnection>scm:git:git at github.com:FasterXML/jackson-dataformat-xml.git</developerConnection>
<url>http://github.com/FasterXML/jackson-dataformat-xml</url>
- <tag>jackson-dataformat-xml-2.9.4</tag>
+ <tag>jackson-dataformat-xml-2.9.6</tag>
</scm>
<properties>
<packageVersion.dir>com/fasterxml/jackson/dataformat/xml</packageVersion.dir>
@@ -85,6 +85,17 @@ Some data-binding types overridden as well (ObjectMapper sub-classed as XmlMappe
<version>5.0.3</version>
</dependency>
+ <!-- 04-Feb-2018, tatu: Finally, Java 9 does not bundle JAXB, not even API;
+ at least include it for tests. May need to include actual dep to
+ API for runtime too, but first for tests
+ -->
+ <dependency>
+ <groupId>javax.xml.bind</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>2.3.0</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
=====================================
release-notes/CREDITS → release-notes/CREDITS-2.x
=====================================
=====================================
release-notes/VERSION → release-notes/VERSION-2.x
=====================================
--- a/release-notes/VERSION
+++ b/release-notes/VERSION-2.x
@@ -4,6 +4,11 @@ Project: jackson-dataformat-xml
= Releases
------------------------------------------------------------------------
+2.9.6 (12-Jun-2018)
+2.9.5 (26-Mar-2018)
+
+No changes since 2.9.4
+
2.9.4 (24-Jan-2018)
- Changed the handling of String deserialization (with addition of `XmlStringDeserializer`)
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/XmlMapper.java
=====================================
--- a/src/main/java/com/fasterxml/jackson/dataformat/xml/XmlMapper.java
+++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/XmlMapper.java
@@ -235,11 +235,10 @@ public class XmlMapper extends ObjectMapper
@SuppressWarnings("resource")
ToXmlGenerator g = getFactory().createGenerator(w0);
super.writeValue(g, value);
- /* NOTE: above call should do flush(); and we should NOT close here.
- * Finally, 'g' has no buffers to release.
- */
+ // NOTE: above call should do flush(); and we should NOT close here.
+ // Finally, 'g' has no buffers to release.
}
-
+
/*
/**********************************************************
/* Overridden methods
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java
=====================================
--- a/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java
+++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/deser/XmlTokenStream.java
@@ -381,9 +381,24 @@ public class XmlTokenStream
while (true) {
switch (_xmlReader.next()) {
case XMLStreamConstants.START_ELEMENT:
+ return (text == null) ? "" : text;
+
case XMLStreamConstants.END_ELEMENT:
case XMLStreamConstants.END_DOCUMENT:
+ // 04-May-2018, tatu: We could easily make <tag></tag> ALSO report
+ // as `null`, by below, but that breaks existing tests so not
+ // done at least until 3.0.
+ /*
+ if (text == null) {
+ if (FromXmlParser.Feature.EMPTY_ELEMENT_AS_NULL.enabledIn(_formatFeatures)) {
+ return null;
+ }
+ return "";
+ }
+ return text;
+ */
return (text == null) ? "" : text;
+
// note: SPACE is ignorable (and seldom seen), not to be included
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
=====================================
src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlSerializerProvider.java
=====================================
--- a/src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlSerializerProvider.java
+++ b/src/main/java/com/fasterxml/jackson/dataformat/xml/ser/XmlSerializerProvider.java
@@ -54,7 +54,9 @@ public class XmlSerializerProvider extends DefaultSerializerProvider
*/
protected XmlSerializerProvider(XmlSerializerProvider src) {
super(src);
- _rootNameLookup = src._rootNameLookup;
+ // 21-May-2018, tatu: As per [dataformat-xml#282], should NOT really copy
+ // root name lookup as that may link back to diff version, configuration
+ _rootNameLookup = new XmlRootNameLookup();
}
/*
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/MapperCopyTest.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/MapperCopyTest.java
@@ -0,0 +1,92 @@
+package com.fasterxml.jackson.dataformat.xml;
+
+import java.io.*;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
+import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider;
+import com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup;
+
+public class MapperCopyTest extends XmlTestBase
+{
+ @JacksonXmlRootElement(localName = "AnnotatedName")
+ static class Pojo282
+ {
+ public int a = 3;
+ }
+
+ public void testMapperCopy()
+ {
+ XmlMapper mapper1 = new XmlMapper();
+ mapper1.setXMLTextElementName("foo");
+ mapper1.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
+ mapper1.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+
+ XmlMapper mapper2 = mapper1.copy();
+ assertNotSame(mapper1, mapper2);
+ XmlFactory xf1 = mapper1.getFactory();
+ XmlFactory xf2 = mapper2.getFactory();
+ assertNotSame(xf1, xf2);
+ assertEquals(XmlFactory.class, xf2.getClass());
+
+ // and incomplete copy as well
+ assertEquals(xf1.getXMLTextElementName(), xf2.getXMLTextElementName());
+ assertEquals(xf1._xmlGeneratorFeatures, xf2._xmlGeneratorFeatures);
+ assertEquals(xf1._xmlParserFeatures, xf2._xmlParserFeatures);
+
+ SerializationConfig sc1 = mapper1.getSerializationConfig();
+ SerializationConfig sc2 = mapper2.getSerializationConfig();
+ assertNotSame(sc1, sc2);
+ assertEquals(
+ "serialization features did not get copied",
+ sc1.getSerializationFeatures(),
+ sc2.getSerializationFeatures()
+ );
+ }
+
+ public void testSerializerProviderCopy() {
+ DefaultSerializerProvider provider = new XmlSerializerProvider(new XmlRootNameLookup());
+ DefaultSerializerProvider copy = provider.copy();
+ assertNotSame(provider, copy);
+ }
+
+ public void testMapperSerialization() throws Exception
+ {
+ XmlMapper mapper1 = newMapper();
+ mapper1.setXMLTextElementName("foo");
+ assertEquals("foo", mapper1.getFactory().getXMLTextElementName());
+
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(bytes);
+ objectStream.writeObject(mapper1);
+ objectStream.close();
+
+ ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
+ XmlMapper mapper2 = (XmlMapper) input.readObject();
+ input.close();
+
+ assertEquals("foo", mapper2.getFactory().getXMLTextElementName());
+ }
+
+ // [dataformat-xml#282]
+ public void testCopyWith() throws Exception
+ {
+ XmlMapper xmlMapper = newMapper();
+ final ObjectMapper xmlMapperNoAnno = xmlMapper.copy()
+ .disable(MapperFeature.USE_ANNOTATIONS)
+ .disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+
+ String xml1 = xmlMapper.writeValueAsString(new Pojo282());
+ String xml2 = xmlMapperNoAnno.writeValueAsString(new Pojo282());
+
+ if (!xml1.contains("AnnotatedName")) {
+ fail("Should use name 'AnnotatedName', xml = "+xml1);
+ }
+ if (!xml2.contains("Pojo282")
+ || xml2.contains("AnnotatedName")) {
+ fail("Should NOT use name 'AnnotatedName' but 'Pojo282', xml = "+xml1);
+ }
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/VersionInfoTest.java
=====================================
--- a/src/test/java/com/fasterxml/jackson/dataformat/xml/VersionInfoTest.java
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/VersionInfoTest.java
@@ -1,15 +1,7 @@
package com.fasterxml.jackson.dataformat.xml;
-import java.io.*;
-
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.Versioned;
-import com.fasterxml.jackson.databind.SerializationConfig;
-import com.fasterxml.jackson.databind.SerializationFeature;
-import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
-import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
-import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider;
-import com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup;
public class VersionInfoTest extends XmlTestBase
{
@@ -18,63 +10,6 @@ public class VersionInfoTest extends XmlTestBase
assertVersion(new XmlMapper());
assertVersion(new XmlFactory());
}
-
- // @since 2.1
- // [Issue#48]: ObjectMapper.copy()
- public void testMapperCopy()
- {
- XmlMapper mapper1 = new XmlMapper();
- mapper1.setXMLTextElementName("foo");
- mapper1.configure(ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true);
- mapper1.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
-
- XmlMapper mapper2 = mapper1.copy();
- assertNotSame(mapper1, mapper2);
- XmlFactory xf1 = mapper1.getFactory();
- XmlFactory xf2 = mapper2.getFactory();
- assertNotSame(xf1, xf2);
- assertEquals(XmlFactory.class, xf2.getClass());
-
- // and [Issue#48] as well, incomplete copy...
- assertEquals(xf1.getXMLTextElementName(), xf2.getXMLTextElementName());
- assertEquals(xf1._xmlGeneratorFeatures, xf2._xmlGeneratorFeatures);
- assertEquals(xf1._xmlParserFeatures, xf2._xmlParserFeatures);
-
- // and [Issue#233]
- SerializationConfig sc1 = mapper1.getSerializationConfig();
- SerializationConfig sc2 = mapper2.getSerializationConfig();
- assertNotSame(sc1, sc2);
- assertEquals(
- "serialization features did not get copied",
- sc1.getSerializationFeatures(),
- sc2.getSerializationFeatures()
- );
- }
-
- public void testSerializerProviderCopy() {
- DefaultSerializerProvider provider = new XmlSerializerProvider(new XmlRootNameLookup());
- DefaultSerializerProvider copy = provider.copy();
- assertNotSame(provider, copy);
- }
-
- // Another test for [Issue#48]
- public void testMapperSerialization() throws Exception
- {
- XmlMapper mapper1 = new XmlMapper();
- mapper1.setXMLTextElementName("foo");
- assertEquals("foo", mapper1.getFactory().getXMLTextElementName());
-
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- ObjectOutputStream objectStream = new ObjectOutputStream(bytes);
- objectStream.writeObject(mapper1);
- objectStream.close();
-
- ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()));
- XmlMapper mapper2 = (XmlMapper) input.readObject();
- input.close();
-
- assertEquals("foo", mapper2.getFactory().getXMLTextElementName());
- }
/*
/**********************************************************
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java
=====================================
--- a/src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/XmlTestBase.java
@@ -6,8 +6,9 @@ import java.util.Arrays;
import junit.framework.TestCase;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+
import com.fasterxml.jackson.core.*;
-import com.fasterxml.jackson.databind.ObjectMapper;
+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
public abstract class XmlTestBase
@@ -139,6 +140,31 @@ public abstract class XmlTestBase
i = value;
}
}
+
+ // since 2.9.6
+ public static class Point {
+ public int x, y;
+
+ protected Point() { } // for deser
+ public Point(int x0, int y0) {
+ x = x0;
+ y = y0;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof Point)) {
+ return false;
+ }
+ Point other = (Point) o;
+ return (other.x == x) && (other.y == y);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[x=%d, y=%d]", x, y);
+ }
+ }
/*
/**********************************************************
@@ -183,7 +209,7 @@ public abstract class XmlTestBase
super();
}
- protected static ObjectMapper newObjectMapper() {
+ protected static XmlMapper newMapper() {
return new XmlMapper();
}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java
=====================================
--- a/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/CaseInsensitiveDeserTest.java
@@ -30,9 +30,9 @@ public class CaseInsensitiveDeserTest extends XmlTestBase
/********************************************************
*/
- private final ObjectMapper MAPPER = newObjectMapper();
+ private final ObjectMapper MAPPER = newMapper();
- private final ObjectMapper INSENSITIVE_MAPPER = newObjectMapper()
+ private final ObjectMapper INSENSITIVE_MAPPER = newMapper()
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
public void testCaseInsensitive1036() throws Exception
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/Issue274PropertyNameTest.java
@@ -0,0 +1,65 @@
+package com.fasterxml.jackson.dataformat.xml.deser;
+
+import com.fasterxml.jackson.databind.*;
+
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+// [dataformat-xml#274]: Actually passes... can not reproduce failure
+public class Issue274PropertyNameTest extends XmlTestBase
+{
+ private static final String XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<dataroot xmlns:od=\"urn:schemas-microsoft-com:officedata\" generated=\"2017-06-07T10:11:20\">\n" +
+ " <Event>\n" +
+ " <EventId>34906566143035</EventId>\n" +
+ " </Event>\n" +
+ "</dataroot>";
+
+ static class Event {
+ @JacksonXmlProperty(localName = "EventId")
+ private String EventId;
+
+ public String getEventId() {
+ return EventId;
+ }
+
+ public void setEventId(String eventId) {
+ this.EventId = eventId;
+ }
+ }
+
+ @JacksonXmlRootElement(localName = "dataroot")
+ static class RootObject {
+ @JacksonXmlProperty(localName = "Event")
+ Event event;
+
+ @JacksonXmlProperty(localName = "generated")
+ String generated;
+ }
+
+ /*
+ /********************************************************
+ /* Test methods
+ /********************************************************
+ */
+
+ // [dataformat-xml#274]
+ public void testIssue274() throws Exception
+ {
+ final ObjectMapper xm = newMapper()
+
+ // serialization features
+// xm.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+// xm.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
+
+ .enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)
+ //this is for deserialization only and means we don't need to camelCase xml property names
+ .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
+ ;
+
+ RootObject obj = xm.readValue(XML, RootObject.class);
+ assertNotNull(obj);
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsGenericTest.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsGenericTest.java
@@ -0,0 +1,142 @@
+package com.fasterxml.jackson.dataformat.xml.deser;
+
+import com.fasterxml.jackson.annotation.JsonSetter;
+import com.fasterxml.jackson.annotation.Nulls;
+import com.fasterxml.jackson.core.type.TypeReference;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+
+// Copied from `com.fasterxml.jackson.databind.deser.filter.` in `jackson-databind`
+public class NullConversionsGenericTest extends XmlTestBase
+{
+ static class PointWrapper {
+ @JsonSetter(nulls=Nulls.AS_EMPTY)
+ public Point p;
+ }
+
+ static class GeneralEmpty<T> {
+ // 09-Feb-2017, tatu: Should only need annotation either for field OR setter, not both:
+// @JsonSetter(nulls=Nulls.AS_EMPTY)
+ T value;
+
+ protected GeneralEmpty() { }
+ public GeneralEmpty(T v) { value = v; }
+
+ @JsonSetter(nulls=Nulls.AS_EMPTY)
+ public void setValue(T v) {
+ value = v;
+ }
+
+ public T getValue() { return value; }
+ }
+
+ static class NoCtorWrapper {
+ @JsonSetter(nulls=Nulls.AS_EMPTY)
+ public NoCtorPOJO value;
+ }
+
+ static class NoCtorPOJO {
+ public NoCtorPOJO(boolean b) { }
+ }
+
+ /*
+ /**********************************************************
+ /* Test methods
+ /**********************************************************
+ */
+
+ private final XmlMapper MAPPER = newMapper();
+
+ private final static String EMPTY_XML = "<GeneralEmpty><value /></GeneralEmpty>";
+
+ public void testNullsToEmptyPojo() throws Exception
+ {
+ PointWrapper pw = MAPPER.readValue("<PointWrapper><p /></PointWrapper>",
+ PointWrapper.class);
+ assertNotNull(pw);
+ assertNotNull(pw.p);
+ assertEquals(0, pw.p.x);
+ assertEquals(0, pw.p.y);
+ }
+
+ public void testNullsToGenericPojo() throws Exception
+ {
+ String xml = MAPPER.writeValueAsString(new GeneralEmpty<Point>(new Point(1, 2)));
+ GeneralEmpty<Point> result = MAPPER.readValue(EMPTY_XML,
+ new TypeReference<GeneralEmpty<Point>>() { });
+ assertNotNull(result.value);
+ Point p = result.value;
+ assertEquals(0, p.x);
+ assertEquals(0, p.y);
+
+ // and then also failing case with no suitable creator:
+ try {
+ /* NoCtorWrapper nogo =*/ MAPPER.readValue(EMPTY_XML,
+ NoCtorWrapper.class);
+ fail("Should not pass");
+ } catch (JsonMappingException e) {
+ verifyException(e, "Cannot create empty instance");
+ }
+ }
+
+ // 04-May-2018, tatu: In theory could be supportable, but wrapping (or not)
+ // of Collections, other requirements, make it... not that easy.
+/*
+ public void testNullsToEmptyCollection() throws Exception
+ {
+ GeneralEmpty<List<String>> result = MAPPER.readValue(EMPTY_XML,
+ new TypeReference<GeneralEmpty<List<String>>>() { });
+ assertNotNull(result.value);
+ assertEquals(0, result.value.size());
+
+ // but also non-String type, since impls vary
+ GeneralEmpty<List<Integer>> result2 = MAPPER.readValue(EMPTY_XML,
+ new TypeReference<GeneralEmpty<List<Integer>>>() { });
+ assertNotNull(result2.value);
+ assertEquals(0, result2.value.size());
+ }
+ */
+
+ // 04-May-2018, tatu: Maps and XML do not mix well, alas:
+ /*
+ public void testNullsToEmptyMap() throws Exception
+ {
+ GeneralEmpty<Map<String,String>> result = MAPPER.readValue(EMPTY_XML,
+ new TypeReference<GeneralEmpty<Map<String,String>>>() { });
+ assertNotNull(result.value);
+ assertEquals(0, result.value.size());
+ }
+ */
+
+ public void testNullsToEmptyArrays() throws Exception
+ {
+ final String doc = EMPTY_XML;
+
+ GeneralEmpty<Object[]> result = MAPPER.readValue(doc,
+ new TypeReference<GeneralEmpty<Object[]>>() { });
+ assertNotNull(result.value);
+ assertEquals(0, result.value.length);
+
+ GeneralEmpty<String[]> result2 = MAPPER.readValue(doc,
+ new TypeReference<GeneralEmpty<String[]>>() { });
+ assertNotNull(result2.value);
+ assertEquals(0, result2.value.length);
+
+ GeneralEmpty<int[]> result3 = MAPPER.readValue(doc,
+ new TypeReference<GeneralEmpty<int[]>>() { });
+ assertNotNull(result3.value);
+ assertEquals(0, result3.value.length);
+
+ GeneralEmpty<double[]> result4 = MAPPER.readValue(doc,
+ new TypeReference<GeneralEmpty<double[]>>() { });
+ assertNotNull(result4.value);
+ assertEquals(0, result4.value.length);
+
+ GeneralEmpty<boolean[]> result5 = MAPPER.readValue(doc,
+ new TypeReference<GeneralEmpty<boolean[]>>() { });
+ assertNotNull(result5.value);
+ assertEquals(0, result5.value.length);
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NullConversionsSkipTest.java
@@ -0,0 +1,106 @@
+package com.fasterxml.jackson.dataformat.xml.deser;
+
+import com.fasterxml.jackson.annotation.JsonSetter;
+import com.fasterxml.jackson.annotation.Nulls;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+
+// for [databind#1402]; configurable null handling, specifically with SKIP
+public class NullConversionsSkipTest extends XmlTestBase
+{
+ static class NullSkipField {
+ public String nullsOk = "a";
+
+ @JsonSetter(nulls=Nulls.SKIP)
+ public String noNulls = "b";
+ }
+
+ static class NullSkipMethod {
+ String _nullsOk = "a";
+ String _noNulls = "b";
+
+ public void setNullsOk(String v) {
+ _nullsOk = v;
+ }
+
+ @JsonSetter(nulls=Nulls.SKIP)
+ public void setNoNulls(String v) {
+ _noNulls = v;
+ }
+ }
+
+ static class StringValue {
+ String value = "default";
+
+ public void setValue(String v) {
+ value = v;
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Test methods, straight annotation
+ /**********************************************************
+ */
+
+ private final XmlMapper MAPPER = newMapper();
+
+ public void testSkipNullField1() throws Exception
+ {
+ // first, ok if assigning non-null to not-nullable, null for nullable
+ NullSkipField result = MAPPER.readValue(
+//"<NullSkipField><noNulls>foo</noNulls><nullsOk></nullsOk></NullSkipField>",
+"<NullSkipField><noNulls>foo</noNulls><nullsOk /></NullSkipField>",
+ NullSkipField.class);
+ assertEquals("foo", result.noNulls);
+ assertNull(result.nullsOk);
+ }
+
+ public void testSkipNullField2() throws Exception
+ {
+ // and then see that nulls are not ok for non-nullable
+ NullSkipField result = MAPPER.readValue("<NullSkipField><noNulls /></NullSkipField>",
+ NullSkipField.class);
+ assertEquals("b", result.noNulls);
+ assertEquals("a", result.nullsOk);
+ }
+
+ public void testSkipNullMethod1() throws Exception
+ {
+ NullSkipMethod result = MAPPER.readValue(
+//"<NullSkipMethod><noNulls>foo<noNulls><nullsOk></nullsOk></NullSkipMethod>",
+"<NullSkipMethod><noNulls>foo</noNulls><nullsOk /></NullSkipMethod>",
+ NullSkipMethod.class);
+ assertEquals("foo", result._noNulls);
+ assertNull(result._nullsOk);
+ }
+
+ public void testSkipNullMethod2() throws Exception
+ {
+ NullSkipMethod result = MAPPER.readValue("<NullSkipMethod><noNulls /></NullSkipMethod>",
+ NullSkipMethod.class);
+ assertEquals("b", result._noNulls);
+ assertEquals("a", result._nullsOk);
+ }
+
+ /*
+ /**********************************************************
+ /* Test methods, defaulting
+ /**********************************************************
+ */
+
+ public void testSkipNullWithDefaults() throws Exception
+ {
+// String doc = "<StringValue><value></value></StringValue>";
+ String doc = "<StringValue><value /></StringValue>";
+ StringValue result = MAPPER.readValue(doc, StringValue.class);
+ assertNull(result.value);
+
+ ObjectMapper mapper = newMapper();
+ mapper.configOverride(String.class)
+ .setSetterInfo(JsonSetter.Value.forValueNulls(Nulls.SKIP));
+ result = mapper.readValue(doc, StringValue.class);
+ assertEquals("default", result.value);
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/deser/builder/BuilderSimpleTest.java
@@ -0,0 +1,365 @@
+package com.fasterxml.jackson.dataformat.xml.deser.builder;
+
+import java.util.*;
+
+import com.fasterxml.jackson.annotation.*;
+
+import com.fasterxml.jackson.core.Version;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
+import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+
+public class BuilderSimpleTest extends XmlTestBase
+{
+ // // Simple 2-property value class, builder with standard naming
+
+ @JsonDeserialize(builder=SimpleBuilderXY.class)
+ static class ValueClassXY
+ {
+ final int _x, _y;
+
+ protected ValueClassXY(int x, int y) {
+ _x = x+1;
+ _y = y+1;
+ }
+ }
+
+ static class SimpleBuilderXY
+ {
+ public int x, y;
+
+ public SimpleBuilderXY withX(int x0) {
+ this.x = x0;
+ return this;
+ }
+
+ public SimpleBuilderXY withY(int y0) {
+ this.y = y0;
+ return this;
+ }
+
+ public ValueClassXY build() {
+ return new ValueClassXY(x, y);
+ }
+ }
+
+ // // 3-property value, with more varied builder
+
+ @JsonDeserialize(builder=BuildABC.class)
+ static class ValueClassABC
+ {
+ final int a, b, c;
+
+ protected ValueClassABC(int a, int b, int c) {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+ }
+
+ @JsonIgnoreProperties({ "d" })
+ static class BuildABC
+ {
+ public int a; // to be used as is
+ private int b, c;
+
+ @JsonProperty("b")
+ public BuildABC assignB(int b0) {
+ this.b = b0;
+ return this;
+ }
+
+ // Also ok NOT to return 'this'
+ @JsonSetter("c")
+ public void c(int c0) {
+ this.c = c0;
+ }
+
+ public ValueClassABC build() {
+ return new ValueClassABC(a, b, c);
+ }
+ }
+
+ // // Then Builder that is itself immutable
+
+ @JsonDeserialize(builder=BuildImmutable.class)
+ static class ValueImmutable
+ {
+ final int value;
+ protected ValueImmutable(int v) { value = v; }
+ }
+
+ static class BuildImmutable {
+ private final int value;
+
+ private BuildImmutable() { this(0); }
+ private BuildImmutable(int v) {
+ value = v;
+ }
+ public BuildImmutable withValue(int v) {
+ return new BuildImmutable(v);
+ }
+ public ValueImmutable build() {
+ return new ValueImmutable(value);
+ }
+ }
+ // And then with custom naming:
+
+ @JsonDeserialize(builder=BuildFoo.class)
+ static class ValueFoo
+ {
+ final int value;
+ protected ValueFoo(int v) { value = v; }
+ }
+
+ @JsonPOJOBuilder(withPrefix="foo", buildMethodName="construct")
+ static class BuildFoo {
+ private int value;
+
+ public BuildFoo fooValue(int v) {
+ value = v;
+ return this;
+ }
+ public ValueFoo construct() {
+ return new ValueFoo(value);
+ }
+ }
+
+
+ // for [databind#761]
+
+ @JsonDeserialize(builder=ValueInterfaceBuilder.class)
+ interface ValueInterface {
+ int getX();
+ }
+
+ @JsonDeserialize(builder=ValueInterface2Builder.class)
+ interface ValueInterface2 {
+ int getX();
+ }
+
+ static class ValueInterfaceImpl implements ValueInterface
+ {
+ final int _x;
+
+ protected ValueInterfaceImpl(int x) {
+ _x = x+1;
+ }
+
+ @Override
+ public int getX() {
+ return _x;
+ }
+ }
+
+ static class ValueInterface2Impl implements ValueInterface2
+ {
+ final int _x;
+
+ protected ValueInterface2Impl(int x) {
+ _x = x+1;
+ }
+
+ @Override
+ public int getX() {
+ return _x;
+ }
+ }
+
+ static class ValueInterfaceBuilder
+ {
+ public int x;
+
+ public ValueInterfaceBuilder withX(int x0) {
+ this.x = x0;
+ return this;
+ }
+
+ public ValueInterface build() {
+ return new ValueInterfaceImpl(x);
+ }
+ }
+
+ static class ValueInterface2Builder
+ {
+ public int x;
+
+ public ValueInterface2Builder withX(int x0) {
+ this.x = x0;
+ return this;
+ }
+
+ // should also be ok: more specific type
+ public ValueInterface2Impl build() {
+ return new ValueInterface2Impl(x);
+ }
+ }
+
+ // [databind#777]
+ @JsonDeserialize(builder = SelfBuilder777.class)
+ @JsonPOJOBuilder(buildMethodName = "", withPrefix = "with")
+ static class SelfBuilder777 {
+ public int x;
+
+ public SelfBuilder777 withX(int value) {
+ x = value;
+ return this;
+ }
+ }
+
+ // Won't work well with XML, omit
+ // [databind#822]
+ /*
+ @JsonPOJOBuilder(buildMethodName = "build", withPrefix = "with")
+ static class ValueBuilder822
+
+ @JsonDeserialize(builder = ValueBuilder822.class)
+ static class ValueClass822
+ */
+
+ protected static class NopModule1557 extends com.fasterxml.jackson.databind.Module
+ {
+ @Override
+ public String getModuleName() {
+ return "NopModule";
+ }
+
+ @Override
+ public Version version() {
+ return Version.unknownVersion();
+ }
+
+ @Override
+ public void setupModule(SetupContext setupContext) {
+ // This annotation introspector has no opinion about builders, make sure it doesn't interfere
+ setupContext.insertAnnotationIntrospector(new NopAnnotationIntrospector() {
+ private static final long serialVersionUID = 1L;
+ @Override
+ public Version version() {
+ return Version.unknownVersion();
+ }
+ });
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Unit tests
+ /**********************************************************
+ */
+
+ private final XmlMapper MAPPER = newMapper();
+
+ public void testSimple() throws Exception
+ {
+ String doc = "<ValueClassXY><x>1</x><y>2</y></ValueClassXY>";
+ Object o = MAPPER.readValue(doc, ValueClassXY.class);
+ assertNotNull(o);
+ assertSame(ValueClassXY.class, o.getClass());
+ ValueClassXY value = (ValueClassXY) o;
+ // note: ctor adds one to both values
+ assertEquals(value._x, 2);
+ assertEquals(value._y, 3);
+ }
+
+ // related to [databind#1214]
+ public void testSimpleWithIgnores() throws Exception
+ {
+ // 'z' is unknown, and would fail by default:
+ String doc = "<ValueClassXY><x>1</x><y>2</y><z>4</z></ValueClassXY>";
+ Object o = null;
+
+ try {
+ o = MAPPER.readValue(doc, ValueClassXY.class);
+ fail("Should not pass");
+ } catch (UnrecognizedPropertyException e) {
+ assertEquals("z", e.getPropertyName());
+ verifyException(e, "Unrecognized field \"z\"");
+ }
+
+ // but with config overrides should pass
+ ObjectMapper ignorantMapper = newMapper();
+ ignorantMapper.configOverride(SimpleBuilderXY.class)
+ .setIgnorals(JsonIgnoreProperties.Value.forIgnoreUnknown(true));
+ o = ignorantMapper.readValue(doc, ValueClassXY.class);
+ assertNotNull(o);
+ assertSame(ValueClassXY.class, o.getClass());
+ ValueClassXY value = (ValueClassXY) o;
+ // note: ctor adds one to both values
+ assertEquals(value._x, 2);
+ assertEquals(value._y, 3);
+ }
+
+ public void testMultiAccess() throws Exception
+ {
+ String doc = "<ValueClassABC><c>3</c> <a>2</a> <b>-9</b></ValueClassABC>";
+ ValueClassABC value = MAPPER.readValue(doc, ValueClassABC.class);
+ assertNotNull(value);
+ assertEquals(2, value.a);
+ assertEquals(-9, value.b);
+ assertEquals(3, value.c);
+
+ // also, since we can ignore some properties:
+ value = MAPPER.readValue("<ValueClassABC><c>3</c>\n"
+ +"<d>5</d><b>-9</b></ValueClassABC>",
+ ValueClassABC.class);
+ assertNotNull(value);
+ assertEquals(0, value.a);
+ assertEquals(-9, value.b);
+ assertEquals(3, value.c);
+ }
+
+ // test for Immutable builder, to ensure return value is used
+ public void testImmutable() throws Exception
+ {
+ ValueImmutable value = MAPPER.readValue("<ValueImmutable><value>13</value></ValueImmutable>",
+ ValueImmutable.class);
+ assertEquals(13, value.value);
+ }
+
+ // test with custom 'with-prefix'
+ public void testCustomWith() throws Exception
+ {
+ ValueFoo value = MAPPER.readValue("<ValueFoo><value>1</value></ValueFoo>", ValueFoo.class);
+ assertEquals(1, value.value);
+ }
+
+ // for [databind#761]
+
+ public void testBuilderMethodReturnMoreGeneral() throws Exception
+ {
+ ValueInterface value = MAPPER.readValue("<ValueInterface><x>1</x></ValueInterface>", ValueInterface.class);
+ assertEquals(2, value.getX());
+ }
+
+ public void testBuilderMethodReturnMoreSpecific() throws Exception
+ {
+ final String json = "<ValueInterface2><x>1</x></ValueInterface2>}";
+ ValueInterface2 value = MAPPER.readValue(json, ValueInterface2.class);
+ assertEquals(2, value.getX());
+ }
+
+ public void testSelfBuilder777() throws Exception
+ {
+ SelfBuilder777 result = MAPPER.readValue("<SelfBuilder777><x>3</x></SelfBuilder777>'",
+ SelfBuilder777.class);
+ assertNotNull(result);
+ assertEquals(3, result.x);
+ }
+
+ // Won't work well with XML, omit:
+// public void testWithAnySetter822() throws Exception
+
+ public void testPOJOConfigResolution1557() throws Exception
+ {
+ final String json = "<ValueFoo><value>1</value></ValueFoo>";
+ MAPPER.registerModule(new NopModule1557());
+ ValueFoo value = MAPPER.readValue(json, ValueFoo.class);
+ assertEquals(1, value.value);
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/CaseInsensitiveDeser273Test.java
=====================================
--- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/CaseInsensitiveDeser273Test.java
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/CaseInsensitiveDeser273Test.java
@@ -1,6 +1,6 @@
package com.fasterxml.jackson.dataformat.xml.failing;
-import java.util.ArrayList;
+import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@@ -18,7 +18,12 @@ public class CaseInsensitiveDeser273Test extends XmlTestBase
public String taskId;
@JacksonXmlElementWrapper(useWrapping = false)
- public ArrayList<Depot273> element;
+ public List<Depot273> element;
+
+ public void setElement(List<Depot273> l) {
+//System.err.println("setElement: "+l);
+ element = l;
+ }
}
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -26,8 +31,18 @@ public class CaseInsensitiveDeser273Test extends XmlTestBase
{
@JacksonXmlProperty(isAttribute = true)
public String number;
+
@JacksonXmlProperty(isAttribute = true)
public String name;
+
+ public void setNumber(String n) {
+//System.err.println("SetNumber: '"+n+"'");
+ number = n;
+ }
+ public void setName(String n) {
+//System.err.println("setName: '"+n+"'");
+ name = n;
+ }
}
/*
@@ -36,21 +51,21 @@ public class CaseInsensitiveDeser273Test extends XmlTestBase
/********************************************************
*/
- private final ObjectMapper INSENSITIVE_MAPPER = newObjectMapper()
+ private final ObjectMapper INSENSITIVE_MAPPER = newMapper()
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
// [dataformat-xml#273]
public void testCaseInsensitiveComplex() throws Exception
{
final String DOC =
-"<AcResponse Command='show depots' TaskId='1260'>\n"+
+"<Depots273 Command='show depots' TaskId='1260'>\n"+
" <Element Number='1' Name='accurev' Slice='1'\n"+
"exclusiveLocking='false' case='insensitive' locWidth='128'"+
"></Element>\n"+
" <Element Number='2' Name='second accurev' Slice='2'\n"+
"exclusiveLocking='false' case='insensitive' locWidth='128'\n"+
"></Element>\n"+
-"</AcResponse>"
+"</Depots273>"
;
Depots273 result = INSENSITIVE_MAPPER.readValue(DOC, Depots273.class);
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser294Test.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ListDeser294Test.java
@@ -0,0 +1,59 @@
+package com.fasterxml.jackson.dataformat.xml.failing;
+
+import java.util.*;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+public class ListDeser294Test extends XmlTestBase
+{
+ @JacksonXmlRootElement(localName = "levels")
+ static class RootLevel {
+ @JacksonXmlElementWrapper(useWrapping = false)
+ @JacksonXmlProperty(localName = "sublevel")
+ public List<Sublevel> sublevels = new ArrayList<>();
+ }
+
+ @JsonPropertyOrder({ "id", "sublevel" }) // fails
+// @JsonPropertyOrder({ "sublevel", "id" }) // works
+ static class Sublevel {
+ public Integer id;
+ public String sublevel;
+ }
+
+ /*
+ /**********************************************************************
+ /* Test methods
+ /**********************************************************************
+ */
+
+ private final XmlMapper MAPPER = newMapper();
+
+ public void testNestedLists294() throws Exception
+ {
+ RootLevel tree = new RootLevel();
+ tree.sublevels.add(_newSublevel(1, "Name A"));
+ tree.sublevels.add(_newSublevel(2, "Name B"));
+ String xml = MAPPER
+ .writerWithDefaultPrettyPrinter()
+ .writeValueAsString(tree);
+//System.err.println("XML:\n"+xml);
+ RootLevel resTree = MAPPER.readValue(xml, RootLevel.class);
+ assertNotNull(resTree);
+ assertNotNull(resTree.sublevels);
+ assertEquals(2, resTree.sublevels.size());
+ assertEquals("Name B", resTree.sublevels.get(1).sublevel);
+ }
+
+ private Sublevel _newSublevel(Integer id, String sublevel) {
+ Sublevel res = new Sublevel();
+ res.id = id;
+ res.sublevel = sublevel;
+ return res;
+ }
+}
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java
=====================================
--- a/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/failing/PolymorphicIssue4Test.java
@@ -62,33 +62,20 @@ public class PolymorphicIssue4Test extends XmlTestBase
/*
/**********************************************************
- /* Set up
+ /* Test methods
/**********************************************************
*/
- protected XmlMapper _xmlMapper;
+ protected final XmlMapper MAPPER = newMapper();
- // let's actually reuse XmlMapper to make things bit faster
- @Override
- public void setUp() throws Exception {
- super.setUp();
- _xmlMapper = new XmlMapper();
- }
-
- /*
- /**********************************************************
- /* Unit tests
- /**********************************************************
- */
-
/* 19-Dec-2010, tatu: Let's hold off these tests, due to issues with inclusions.
*/
// Does not work since array wrapping is not explicitly forced (unlike with collection
// property of a bean
public void testAsClassArray() throws Exception
{
- String xml = _xmlMapper.writeValueAsString(new SubTypeWithClassArray("Foobar"));
- Object result = _xmlMapper.readValue(xml, BaseTypeWithClassArray.class);
+ String xml = MAPPER.writeValueAsString(new SubTypeWithClassArray("Foobar"));
+ Object result = MAPPER.readValue(xml, BaseTypeWithClassArray.class);
assertNotNull(result);
assertEquals(SubTypeWithClassArray.class, result.getClass());
assertEquals("Foobar", ((SubTypeWithClassArray) result).name);
@@ -98,11 +85,10 @@ public class PolymorphicIssue4Test extends XmlTestBase
// array context when writing...
public void testAsWrappedClassArray() throws Exception
{
- String xml = _xmlMapper.writeValueAsString(new ClassArrayWrapper("Foobar"));
- ClassArrayWrapper result = _xmlMapper.readValue(xml, ClassArrayWrapper.class);
+ String xml = MAPPER.writeValueAsString(new ClassArrayWrapper("Foobar"));
+ ClassArrayWrapper result = MAPPER.readValue(xml, ClassArrayWrapper.class);
assertNotNull(result);
assertEquals(SubTypeWithClassArray.class, result.wrapped.getClass());
assertEquals("Foobar", ((SubTypeWithClassArray) result.wrapped).name);
}
}
-
\ No newline at end of file
=====================================
src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java
=====================================
--- /dev/null
+++ b/src/test/java/com/fasterxml/jackson/dataformat/xml/jaxb/BuilderWithJAXB291Test.java
@@ -0,0 +1,129 @@
+package com.fasterxml.jackson.dataformat.xml.jaxb;
+
+import javax.xml.bind.annotation.XmlElement;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.AnnotationIntrospector;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
+import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
+import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector;
+import com.fasterxml.jackson.dataformat.xml.XmlMapper;
+import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
+
+// Test for [dataformat-xml#291]: works via field, not constructor
+// (name mismatch to fix in test case)
+public class BuilderWithJAXB291Test extends XmlTestBase
+{
+ @JsonDeserialize(builder = Address.AddressBuilder.class)
+ static class Address
+ {
+ private final String address1;
+ private final String city;
+ private final String stateProvince;
+ private final String postalCode;
+ private final String country;
+ private final String county;
+
+ private Address(AddressBuilder addressbuilder) {
+ this.address1 = addressbuilder.address1;
+ this.city = addressbuilder.city;
+ this.stateProvince = addressbuilder.stateProvince;
+ this.postalCode = addressbuilder.postalCode;
+ this.country = addressbuilder.country;
+ this.county = addressbuilder.county;
+ }
+
+ public String getAddress1() {
+ return address1;
+ }
+ public String getCity() {
+ return city;
+ }
+
+ public String getStateProvince() {
+ return stateProvince;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public String getCounty() {
+ return county;
+ }
+
+ @JsonPOJOBuilder(withPrefix = "set")
+ static class AddressBuilder {
+
+ @XmlElement(name = "Address1")
+ final String address1;
+
+ @XmlElement(name = "City")
+ final String city;
+
+ @XmlElement(name = "StateProvince")
+ final String stateProvince;
+
+ @XmlElement(name = "PostalCode")
+ final String postalCode;
+
+ @XmlElement(name = "Country")
+ final String country;
+
+ @XmlElement(name = "County")
+ String county;
+
+ @JsonCreator
+ public AddressBuilder(@JsonProperty("address1") String address1, @JsonProperty("city") String city, @JsonProperty("stateProvince") String stateProvince,
+ @JsonProperty("postalCode") String postalCode, @JsonProperty("country") String country) {
+ this.address1 = address1;
+ this.city = city;
+ this.stateProvince = stateProvince;
+ this.postalCode = postalCode;
+ this.country = country;
+ }
+
+ public AddressBuilder setCounty(String county) {
+ this.county = county;
+ return this;
+ }
+
+ public Address build() {
+ return new Address(this);
+ }
+ }
+ }
+
+ /*
+ /**********************************************************************
+ /* Test methods
+ /**********************************************************************
+ */
+
+ public void testBuilder291() throws Exception
+ {
+ final String DOC = "<Address>\n" +
+ " <Address1>111 Foo Bar</Address1>\n" +
+ " <City>San Francisco</City>\n" +
+ " <Country>USA</Country>\n" +
+ " <County>San Francisco</County>\n" +
+ " <StateProvince>CA</StateProvince>\n" +
+ " <PostalCode>94132</PostalCode>\n" +
+ "</Address>";
+
+ XmlMapper mapper = newMapper();
+ XmlJaxbAnnotationIntrospector xmlIntr = new XmlJaxbAnnotationIntrospector(mapper.getTypeFactory());
+ AnnotationIntrospector intr = XmlAnnotationIntrospector.Pair.instance
+ (xmlIntr, new JacksonAnnotationIntrospector());
+ mapper.setAnnotationIntrospector(intr);
+ Address value = mapper.readValue(DOC, Address.class);
+ assertNotNull(value);
+ assertEquals("San Francisco", value.getCity());
+ }
+}
View it on GitLab: https://salsa.debian.org/java-team/jackson-dataformat-xml/compare/451ce9f09a38a61e5e62727734aca6f166a3ad3a...1572d850cfd2c01566dbe904f10a9f9aea31620f
--
View it on GitLab: https://salsa.debian.org/java-team/jackson-dataformat-xml/compare/451ce9f09a38a61e5e62727734aca6f166a3ad3a...1572d850cfd2c01566dbe904f10a9f9aea31620f
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20180817/3f1e724d/attachment.html>
More information about the pkg-java-commits
mailing list