Skip to content

Commit c57d8fd

Browse files
committed
Fix #485
1 parent 61522bf commit c57d8fd

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ All released versions have matching git tags (`jackson-dataformats-text-2.9.4`).
3232

3333
## Status
3434

35-
[![Build (github)](https://github.com/FasterXML/jackson-dataformat-xml/actions/workflows/main.yml/badge.svg)](https://github.com/FasterXML/jackson-dataformat-xml/actions/workflows/main.yml)
36-
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.dataformat/jackson-dataformat-xml/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.dataformat/jackson-dataformat-xml/)
37-
[![Javadoc](https://javadoc.io/badge/com.fasterxml.jackson.dataformat/jackson-dataformat-xml.svg)](http://www.javadoc.io/doc/com.fasterxml.jackson.dataformat/jackson-dataformat-xml)
38-
[![Tidelift](https://tidelift.com/badges/package/maven/com.fasterxml.jackson.dataformat:jackson-dataformat-xml)](https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-dataformat-jackson-dataformat-xml?utm_source=maven-com-fasterxml-jackson-dataformat-jackson-dataformat-xml&utm_medium=referral&utm_campaign=readme)
39-
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/jackson-dataformat-xml.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:jackson-dataformat-xml)
35+
| Type | Status |
36+
| ---- | ------ |
37+
| Build (CI) | [![Build (github)](https://github.com/FasterXML/jackson-dataformat-xml/actions/workflows/main.yml/badge.svg)](https://github.com/FasterXML/jackson-dataformat-xml/actions/workflows/main.yml) |
38+
| Artifact | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.dataformat/jackson-dataformat-xml/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.fasterxml.jackson.dataformat/jackson-dataformat-xml) |
39+
| OSS Sponsorship | [![Tidelift](https://tidelift.com/badges/package/maven/com.fasterxml.jackson.dataformat:jackson-dataformat-xml)](https://tidelift.com/subscription/pkg/maven-com-fasterxml-jackson-dataformat-jackson-dataformat-xml?utm_source=maven-com-fasterxml-jackson-dataformat-jackson-dataformat-xml&utm_medium=referral&utm_campaign=readme) |
40+
| Javadocs | [![Javadoc](https://javadoc.io/badge/com.fasterxml.jackson.dataformat/jackson-dataformat-xml.svg)](http://www.javadoc.io/doc/com.fasterxml.jackson.dataformat/jackson-dataformat-xml) |
41+
| Code coverage (2.13) | [![codecov.io](https://codecov.io/github/FasterXML/jackson-dataformat-xml/coverage.svg?branch=2.13)](https://codecov.io/github/FasterXML/jackson-dataformat-xml?branch=2.13) |
42+
| CodeQ (LGTM.com) | [![LGTM alerts](https://img.shields.io/lgtm/alerts/g/FasterXML/jackson-dataformat-xml.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/FasterXML/jackson-dataformat-xml/alerts/) [![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/FasterXML/jackson-dataformat-xml.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/FasterXML/jackson-dataformat-xml/context:java) |
43+
| Fuzzing | [![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/jackson-dataformat-xml.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:jackson-dataformat-xml) |
4044

4145
## License
4246

@@ -248,6 +252,9 @@ Currently, following limitations exist beyond general Jackson (JSON) limitations
248252
* Mixed Content (elements and text in same element) is not supported in databinding: child content must be either text OR element(s) (attributes are fine)
249253
* While XML namespaces are recognized, and produced on serialization, namespace URIs are NOT verified when deserializing: only local names are matched
250254
* This also means that elements that only differ by namespace cannot be used.
255+
* Root name wrapping support is incomplete (`SerializationFeature.WRAP_ROOT_VALUE` / `DeserializationFeature.UNWRAP_ROOT_VALUE`, so that:
256+
* Serialization DOES NOT add wrapping (at least up to and including 2.13)
257+
* Deserialization DOES unwrap root element (except for Jackson 2.12.x that temporarily removed support altogether -- fixed in 2.13.0)
251258

252259
-----
253260

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Project: jackson-dataformat-xml
2525
actual fix in `jackson-databind)
2626
#483: Explicitly pass ClassLoader of XmlFactory when creating Stax input/output factory,
2727
instead of context ClassLoader
28+
#485: Deserialization with XmlMapper and DeserializationFeature.UNWRAP_ROOT_VALUE
29+
no longer works in 2.12
30+
(reported by ionel-sirbu-crunch@github)
2831
- Rename `XmlFactoryBuilder` methods "inputFactory()"->"xmlInputFactory()",
2932
"outputFactory()" -> "xmlOutputFactory()"
3033
- Woodstox dependency 6.2.6 (from 6.2.4)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ public DefaultDeserializationContext with(DeserializerFactory factory) {
7777
/**********************************************************
7878
*/
7979

80-
// [dataformat-xml#374]: need to remove handling of expected root name unwrapping
81-
// to match serialization
8280
@Override // since 2.12
8381
public Object readRootValue(JsonParser p, JavaType valueType,
8482
JsonDeserializer<Object> deser, Object valueToUpdate)
8583
throws IOException
8684
{
87-
// if (_config.useRootWrapping()) {
88-
// return _unwrapAndDeserialize(p, valueType, deser, valueToUpdate);
89-
// }
85+
// 18-Sep-2021, tatu: Complicated mess; with 2.12, had [dataformat-xml#374]
86+
// to disable handling. With 2.13, via [dataformat-xml#485] undid this change
87+
if (_config.useRootWrapping()) {
88+
return _unwrapAndDeserialize(p, valueType, deser, valueToUpdate);
89+
}
9090
if (valueToUpdate == null) {
9191
return deser.deserialize(p, this);
9292
}

src/test/java/com/fasterxml/jackson/dataformat/xml/misc/RootNameWrapping374Test.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,53 @@
55
import com.fasterxml.jackson.databind.SerializationFeature;
66
import com.fasterxml.jackson.dataformat.xml.*;
77

8+
// Test originally for [dataformat-xml#374] but later (2.13)
9+
// for [dataformat-xml#485]
810
public class RootNameWrapping374Test extends XmlTestBase
911
{
1012
@JsonRootName("Root")
1113
static class Root {
1214
public int id = 1;
1315
}
1416

15-
private final XmlMapper MAPPER = mapperBuilder()
17+
// By default neither adding nor expecting wrapping
18+
private final XmlMapper DEFAULT_MAPPER = newMapper();
19+
20+
// 18-Sep-2021, tatu: Note! WRAP_ROOT_VALUE has not and does not work with XML
21+
// at all, up to and including 2.13.
22+
// But UNWRAP_ROOT_VALUE worked before and after 2.12
23+
// (as per [dataformat-xml#485]).
24+
//
25+
// There is hope that maybe WRAP_ROOT_VALUE should be supportable in future too.
26+
private final XmlMapper WRAPPING_MAPPER = mapperBuilder()
1627
.enable(SerializationFeature.WRAP_ROOT_VALUE)
1728
.enable(DeserializationFeature.UNWRAP_ROOT_VALUE)
1829
.build();
1930

20-
public void testUnwrappedRoundTrip() throws Exception
31+
public void testWriteIgnoresWrapping() throws Exception
32+
{
33+
// Writing is without wrapping no matter what...
34+
String xmlDefault = DEFAULT_MAPPER.writeValueAsString(new Root());
35+
String xmlWrapEnabled = WRAPPING_MAPPER.writeValueAsString(new Root());
36+
37+
assertEquals("<Root><id>1</id></Root>", xmlDefault);
38+
assertEquals(xmlDefault, xmlWrapEnabled);
39+
}
40+
41+
public void testReadWithoutWrapping() throws Exception
2142
{
22-
String xml = MAPPER.writeValueAsString(new Root());
43+
String xml = DEFAULT_MAPPER.writeValueAsString(new Root());
44+
Root result = DEFAULT_MAPPER.readValue(xml, Root.class);
45+
assertNotNull(result);
46+
}
47+
48+
public void testReadWithWrapping() throws Exception
49+
{
50+
String xml = DEFAULT_MAPPER.writeValueAsString(new Root());
2351
assertEquals("<Root><id>1</id></Root>", xml);
24-
//System.err.println("XML: "+xml);
25-
Root result = MAPPER.readValue(xml, Root.class);
52+
53+
String wrapped = "<ignoreMe>"+xml+"</ignoreMe>";
54+
Root result = WRAPPING_MAPPER.readValue(wrapped, Root.class);
2655
assertNotNull(result);
2756
}
2857
}

0 commit comments

Comments
 (0)