Skip to content

Commit 12d54f8

Browse files
authored
Merge branch '2.17' into json-array-serialize
2 parents e763443 + d05688e commit 12d54f8

File tree

9 files changed

+287
-18
lines changed

9 files changed

+287
-18
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<parent>
1010
<groupId>com.fasterxml.jackson</groupId>
1111
<artifactId>jackson-base</artifactId>
12-
<version>2.17.0-SNAPSHOT</version>
12+
<version>2.17.2-SNAPSHOT</version>
1313
</parent>
1414
<groupId>com.fasterxml.jackson.dataformat</groupId>
1515
<artifactId>jackson-dataformat-xml</artifactId>
16-
<version>2.17.0-SNAPSHOT</version>
16+
<version>2.17.2-SNAPSHOT</version>
1717
<name>Jackson-dataformat-XML</name>
1818
<packaging>jar</packaging>
1919
<description>Data format extension for Jackson to offer
@@ -34,7 +34,7 @@ alternative support for serializing POJOs as XML and deserializing XML as pojos.
3434
<!-- And presumably import too? -->
3535

3636
<!-- for Reproducible Builds -->
37-
<project.build.outputTimestamp>2024-02-27T02:19:55Z</project.build.outputTimestamp>
37+
<project.build.outputTimestamp>2024-05-05T02:26:37Z</project.build.outputTimestamp>
3838
</properties>
3939

4040
<dependencies>
@@ -91,7 +91,7 @@ alternative support for serializing POJOs as XML and deserializing XML as pojos.
9191
<dependency>
9292
<groupId>com.fasterxml.woodstox</groupId>
9393
<artifactId>woodstox-core</artifactId>
94-
<version>6.6.1</version>
94+
<version>6.6.2</version>
9595
<exclusions>
9696
<exclusion>
9797
<groupId>javax.xml.stream</groupId>

release-notes/CREDITS-2.x

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,30 @@ Motonori IWAMURO (@vmi)
244244
`XmlBeanSerializerBase#serializeFieldsFiltered()`
245245
(2.16.1)
246246

247+
Dennis Cornwell (@cornwe19)
248+
249+
* Reported #509: Exception when parsing `List`s of mixed content (since 2.13.0)
250+
(2.16.3)
251+
252+
Christopher R. Wicks (@wickstopher)
253+
254+
* Contributed fix for #509: Exception when parsing `List`s of mixed content (since 2.13.0)
255+
(2.16.3)
256+
247257
Arthur Chan (@arthurscchan)
248258

249259
* Reported, contributed fix for #618: `ArrayIndexOutOfBoundsException` thrown for invalid
250260
ending XML string when using JDK default Stax XML parser
251261
(2.17.0)
262+
263+
Alex H (@ahcodedthat)
264+
265+
* Contributed #643: XML serialization of floating-point infinity is incompatible
266+
with JAXB and XML Schema
267+
(2.17.0)
268+
269+
Bas Passon (@bpasson)
270+
271+
* Reported, contributed fix for #646: Deserializing fails when using builder classes
272+
with `Iterable` Collection setters
273+
(2.17.1)

release-notes/VERSION-2.x

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ Project: jackson-dataformat-xml
44
=== Releases ===
55
------------------------------------------------------------------------
66

7-
2.17.0-rc1 (26-Feb-2024)
7+
2.18.0 (not yet released)
8+
9+
No changes since 2.17
10+
11+
2.17.1 (04-May-2024)
12+
13+
#646: Deserializing fails when using builder classes with `Iterable` Collection setters
14+
(fix contributed by Bas P)
15+
* Upgrade Woodstox to 6.6.2 (dependency fixes)
16+
17+
2.17.0 (12-Mar-2024)
818

919
#324: Support use of `xsi:type` for polymorphic serialization
1020
(`ToXmlGenerator.Feature.AUTO_DETECT_XSI_TYPE`)
@@ -18,8 +28,21 @@ Project: jackson-dataformat-xml
1828
(FromXmlParser.Feature.AUTO_DETECT_XSI_TYPE)
1929
#637: `JacksonXmlAnnotationIntrospector.findNamespace()` should
2030
properly merge namespace information
31+
#643: XML serialization of floating-point infinity is incompatible
32+
with JAXB and XML Schema
33+
(contributed by Alex H)
2134
* Upgrade Woodstox to 6.6.1 (latest at the time)
2235

36+
2.16.3 (not yet released)
37+
38+
#509: Exception when parsing `List`s of mixed content (since 2.13.0)
39+
(reported by Dennis C)
40+
(fix contributed by Christopher R. W)
41+
42+
2.16.2 (09-Mar-2024)
43+
44+
No changes since 2.16.1
45+
2346
2.16.1 (24-Dec-2023)
2447

2548
#616: Fix mismatch in `setNextIsUnwrapped(boolean)` in

src/main/java/com/fasterxml/jackson/dataformat/xml/deser/FromXmlParser.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import javax.xml.stream.XMLStreamWriter;
1414

1515
import com.fasterxml.jackson.core.*;
16+
import com.fasterxml.jackson.core.JsonParser.NumberTypeFP;
1617
import com.fasterxml.jackson.core.base.ParserMinimalBase;
1718
import com.fasterxml.jackson.core.exc.StreamConstraintsException;
1819
import com.fasterxml.jackson.core.io.IOContext;
@@ -925,9 +926,17 @@ public JsonToken nextToken() throws IOException
925926
}
926927
// 29-Mar-2021, tatu: This seems like an error condition...
927928
// How should we indicate it? As of 2.13, report as unexpected state
929+
/*
928930
throw _constructError(
929-
"Unexpected non-whitespace text ('"+_currText+"' in Array context: should not occur (or should be handled)"
931+
"Unexpected non-whitespace text ('"+_currText+"') in Array context: should not occur (or should be handled)"
930932
);
933+
*/
934+
935+
// [dataformat-xml#509] 2.13 introduced a defect in which an Exception was thrown above, breaking
936+
// parsing of mixed content arrays (https://github.com/FasterXML/jackson-dataformat-xml/issues/509).
937+
// This exception case was removed to enable continued support of that functionality, but more
938+
// robust state handling may be in order.
939+
// See comment https://github.com/FasterXML/jackson-dataformat-xml/pull/604
931940
}
932941

933942
// If not a leaf (or otherwise ignorable), need to transform into property...
@@ -1219,6 +1228,15 @@ public NumberType getNumberType() throws IOException {
12191228
return NumberType.BIG_INTEGER;
12201229
}
12211230

1231+
/**
1232+
* XML has no notion of natural/native floating-point type (has to be
1233+
* provided externally via Schema or so), so need to ensure we indicate that.
1234+
*/
1235+
@Override // added in 2.17
1236+
public NumberTypeFP getNumberTypeFP() throws IOException {
1237+
return NumberTypeFP.UNKNOWN;
1238+
}
1239+
12221240
@Override
12231241
public Number getNumberValue() throws IOException {
12241242
if (_numTypesValid == NR_UNKNOWN) {

src/main/java/com/fasterxml/jackson/dataformat/xml/ser/ToXmlGenerator.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,37 @@ public enum Feature implements FormatFeature
106106
* @since 2.17
107107
*/
108108
AUTO_DETECT_XSI_TYPE(false),
109+
110+
/**
111+
* Feature that determines how floating-point infinity values are
112+
* serialized.
113+
*<p>
114+
* By default, {@link Float#POSITIVE_INFINITY} and
115+
* {@link Double#POSITIVE_INFINITY} are serialized as {@code Infinity},
116+
* and {@link Float#NEGATIVE_INFINITY} and
117+
* {@link Double#NEGATIVE_INFINITY} are serialized as
118+
* {@code -Infinity}. This is the representation that Java normally
119+
* uses for these values (see {@link Float#toString(float)} and
120+
* {@link Double#toString(double)}), but JAXB and other XML
121+
* Schema-conforming readers won't understand it.
122+
*<p>
123+
* With this feature enabled, these values are instead serialized as
124+
* {@code INF} and {@code -INF}, respectively. This is the
125+
* representation that XML Schema and JAXB use (see the XML Schema
126+
* primitive types
127+
* <a href="https://www.w3.org/TR/xmlschema-2/#float"><code>float</code></a>
128+
* and
129+
* <a href="https://www.w3.org/TR/xmlschema-2/#double"><code>double</code></a>).
130+
*<p>
131+
* When deserializing, Jackson always understands both representations,
132+
* so there is no corresponding
133+
* {@link com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser.Feature}.
134+
*<p>
135+
* Feature is disabled by default for backwards compatibility.
136+
*
137+
* @since 2.17
138+
*/
139+
WRITE_XML_SCHEMA_CONFORMING_FLOATS(false),
109140
;
110141

111142
final boolean _defaultState;
@@ -1174,6 +1205,11 @@ public void writeNumber(long l) throws IOException
11741205
@Override
11751206
public void writeNumber(double d) throws IOException
11761207
{
1208+
if (Double.isInfinite(d) && isEnabled(Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)) {
1209+
writeNumber(d > 0d ? "INF" : "-INF");
1210+
return;
1211+
}
1212+
11771213
_verifyValueWrite("write number");
11781214
if (_nextName == null) {
11791215
handleMissingName();
@@ -1202,6 +1238,11 @@ public void writeNumber(double d) throws IOException
12021238
@Override
12031239
public void writeNumber(float f) throws IOException
12041240
{
1241+
if (Float.isInfinite(f) && isEnabled(Feature.WRITE_XML_SCHEMA_CONFORMING_FLOATS)) {
1242+
writeNumber(f > 0f ? "INF" : "-INF");
1243+
return;
1244+
}
1245+
12051246
_verifyValueWrite("write number");
12061247
if (_nextName == null) {
12071248
handleMissingName();

src/main/java/com/fasterxml/jackson/dataformat/xml/util/TypeUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public class TypeUtil
1111
public static boolean isIndexedType(JavaType type)
1212
{
1313
Class<?> cls = type.getRawClass();
14-
if (type.isContainerType() || type.isIterationType()) {
14+
// 25-Mar-2024, tatu [dataformat-xml#646]: Need to support Iterable too
15+
if (type.isContainerType() || type.isIterationType() || cls == Iterable.class) {
1516
// One special case; byte[] will be serialized as base64-encoded String, not real array, so:
1617
// (actually, ditto for char[]; thought to be a String)
1718
if (cls == byte[].class || cls == char[].class) {
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package com.fasterxml.jackson.dataformat.xml.failing;
1+
package com.fasterxml.jackson.dataformat.xml.deser;
22

33
import java.util.*;
44

55
import org.junit.Test;
66

77
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
8-
98
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
9+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
1010
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
1111
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlText;
1212

@@ -31,6 +31,8 @@ public void setKey(java.lang.String value) {
3131
}
3232

3333
static class MetaData {
34+
@JacksonXmlElementWrapper(useWrapping = false)
35+
@JacksonXmlProperty(localName = "data")
3436
protected List<Data> data;
3537

3638
public List<Data> getData() {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.fasterxml.jackson.dataformat.xml.lists;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
8+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
9+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
10+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
11+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
12+
13+
// [dataformat-xml#646]
14+
public class IterableCollectionBuilder646Test extends XmlTestBase
15+
{
16+
@JsonDeserialize(builder = Parent.Builder.class)
17+
@JacksonXmlRootElement(localName = "parent")
18+
static class Parent {
19+
private final List<Child> children;
20+
21+
Parent(List<Child> children) {
22+
this.children = children;
23+
}
24+
25+
@JsonProperty("child")
26+
@JacksonXmlElementWrapper(useWrapping = false)
27+
public List<Child> getChildren() {
28+
return children;
29+
}
30+
31+
static class Builder {
32+
private final List<Child> children = new ArrayList<>();
33+
34+
@JsonProperty("child")
35+
@JacksonXmlElementWrapper(useWrapping = false)
36+
public Builder children(Iterable<Child> children) {
37+
for (Child c : children) {
38+
this.children.add(c);
39+
}
40+
return this;
41+
}
42+
43+
public Parent build() {
44+
return new Parent(children);
45+
}
46+
}
47+
}
48+
49+
@JsonDeserialize(builder = Child.Builder.class)
50+
@JacksonXmlRootElement(localName = "child")
51+
static class Child {
52+
private final String id;
53+
54+
public Child(String id) {
55+
this.id = id;
56+
}
57+
58+
@JsonProperty("id")
59+
public String getId() {
60+
return id;
61+
}
62+
63+
static class Builder {
64+
private String id;
65+
66+
@JsonProperty("id")
67+
public Builder id(String id) {
68+
this.id = id;
69+
return this;
70+
}
71+
72+
public Child build() {
73+
return new Child(id);
74+
}
75+
}
76+
}
77+
78+
// -- Test Methods --//
79+
private final XmlMapper MAPPER = newMapper();
80+
81+
public void testIssue646() throws Exception {
82+
final String XML = "<parent><child><id>1</id></child></parent>";
83+
Parent parent = MAPPER.readValue(XML, Parent.class);
84+
assertNotNull(parent);
85+
assertNotNull(parent.getChildren());
86+
assertEquals(1, parent.getChildren().size());
87+
}
88+
}

0 commit comments

Comments
 (0)