Skip to content

Commit ce01183

Browse files
committed
Merge branch '2.19' into 3.x
2 parents c4c178b + fe1878b commit ce01183

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Project: jackson-dataformat-xml
66

77
#508: `XmlMapper` is unable to deserialise into an empty record
88
(reported by @protazy)
9+
#714: Root-level `null` handling (via `xsi:nil`) leaves trailing token in
10+
`JsonParser`-exposed token stream
911
#745: Add feature to include `standalone='yes'` in xml declaration
1012
(contributed by @duoduobingbing)
1113

src/main/java/tools/jackson/dataformat/xml/deser/FromXmlParser.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public class FromXmlParser
135135
*/
136136

137137
/**
138-
* Bitfield that indicates which numeric representations
138+
* Bit field that indicates which numeric representations
139139
* have been calculated for the current type
140140
*/
141141
protected int _numTypesValid = NR_UNKNOWN;
@@ -178,6 +178,8 @@ public FromXmlParser(ObjectReadContext readCtxt, IOContext ioCtxt,
178178
// changed in 2.10.2
179179
if (_xmlTokens.hasXsiNil()) {
180180
_nextToken = JsonToken.VALUE_NULL;
181+
// 21-Apr-2025, tatu: [dataformat-xml#714] Must "flush" the stream
182+
_xmlTokens.markAsStreamEnd();
181183
} else {
182184
switch (firstToken) {
183185
case XmlTokenStream.XML_START_ELEMENT:
@@ -474,16 +476,16 @@ public JsonToken nextToken() throws JacksonException
474476
{
475477
JsonToken t = nextToken0();
476478
if (t != null) {
477-
final String loc = (_parsingContext == null) ? "NULL" : String.valueOf(_parsingContext.pathAsPointer());
479+
final String loc = (_parsingContext == null) ? "<null>" : "'"+String.valueOf(_parsingContext.pathAsPointer())+"'";
478480
switch (t) {
479481
case PROPERTY_NAME:
480-
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.PROPERTY_NAME '%s'\n", loc, _parsingContext.currentName());
482+
System.out.printf("FromXmlParser.nextToken() at %s: JsonToken.PROPERTY_NAME '%s'\n", loc, _parsingContext.currentName());
481483
break;
482484
case VALUE_STRING:
483-
System.out.printf("FromXmlParser.nextToken() at '%s': JsonToken.VALUE_STRING '%s'\n", loc, getText());
485+
System.out.printf("FromXmlParser.nextToken() at %s: JsonToken.VALUE_STRING '%s'\n", loc, getText());
484486
break;
485487
default:
486-
System.out.printf("FromXmlParser.nextToken() at '%s': %s\n", loc, t);
488+
System.out.printf("FromXmlParser.nextToken() at %s: %s\n", loc, t);
487489
}
488490
}
489491
return t;

src/main/java/tools/jackson/dataformat/xml/deser/XmlTokenStream.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,6 @@ public int next() throws XMLStreamException
260260
case XML_START_ELEMENT:
261261
System.out.printf(" XmlTokenStream.next(): XML_START_ELEMENT '%s' %s\n", _localName, _loc());
262262
break;
263-
case XML_DELAYED_START_ELEMENT:
264-
System.out.printf(" XmlTokenStream.next(): XML_DELAYED_START_ELEMENT '%s' %s\n", _localName, _loc());
265-
break;
266263
case XML_END_ELEMENT:
267264
// 24-May-2020, tatu: no name available for end element so do not print
268265
System.out.printf(" XmlTokenStream.next(): XML_END_ELEMENT %s\n", _loc());
@@ -397,6 +394,16 @@ protected void pushbackCurrentToken()
397394
_repeatCurrentToken = true;
398395
}
399396

397+
/**
398+
* Method that can be called to mark stream as having reached end of stream.
399+
*
400+
* @since 2.19
401+
*/
402+
protected void markAsStreamEnd()
403+
{
404+
_currentState = XML_END;
405+
}
406+
400407
/**
401408
* Method called to skip any attributes current START_ELEMENT may have,
402409
* so that they are not returned as token.
@@ -451,6 +458,7 @@ private final int _next() throws XMLStreamException
451458
// 08-Jul-2021, tatu: as per [dataformat-xml#467] just skip anything
452459
// element might have, no need to ensure it was empty
453460
_xmlReader.skipElement();
461+
//System.out.println(" XmlTokenStream._next(): Got xsi:nil, skipping element");
454462
return _handleEndElement();
455463
}
456464
if (_nextAttributeIndex < _attributeCount) {
@@ -693,7 +701,7 @@ private final void _checkXsiAttributes() {
693701
int count = _xmlReader.getAttributeCount();
694702
_attributeCount = count;
695703

696-
// [dataformat-xml#354]: xsi:nul handling; at first only if first attribute
704+
// [dataformat-xml#354]: xsi:nil handling; at first only if first attribute
697705
if (count >= 1) {
698706
// [dataformat-xml#468]: may disable xsi:nil processing
699707
if (_cfgProcessXsiNil
@@ -703,6 +711,7 @@ private final void _checkXsiAttributes() {
703711
_nextAttributeIndex = 1;
704712
// but only mark as nil marker if enabled
705713
_xsiNilFound = "true".equals(_xmlReader.getAttributeValue(0));
714+
//System.out.println(" XMLTokenStream._checkXsiAttributes(), _xsiNilFound: "+_xsiNilFound);
706715
return;
707716
}
708717
}
@@ -813,6 +822,8 @@ private final int _handleEndElement()
813822

814823
}
815824
} else {
825+
//System.out.println(" XMLTokenStream._handleEndElement(): no wrapper");
826+
816827
// Not (necessarily) known, as per above, so:
817828
_localName = "";
818829
_namespaceURI = "";

src/test/java/tools/jackson/dataformat/xml/tofix/XsiNilBasic714Test.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import tools.jackson.dataformat.xml.XmlMapper;
88
import tools.jackson.dataformat.xml.XmlReadFeature;
99
import tools.jackson.dataformat.xml.XmlTestUtil;
10-
import tools.jackson.dataformat.xml.testutil.failure.JacksonTestFailureExpected;
1110

1211
import static org.junit.jupiter.api.Assertions.*;
1312

@@ -21,7 +20,6 @@ public class XsiNilBasic714Test extends XmlTestUtil
2120
.build();
2221

2322
// [dataformat-xml#714]: trailing END_OBJECT
24-
@JacksonTestFailureExpected
2523
@Test
2624
public void testRootPojoAsNull() throws Exception
2725
{
@@ -34,7 +32,6 @@ public void testRootPojoAsNull() throws Exception
3432
// [dataformat-xml#468]: Allow disabling xsi:nil special handling
3533

3634
// [dataformat-xml#714]: trailing END_OBJECT
37-
@JacksonTestFailureExpected
3835
@Test
3936
public void testDisableXsiNilRootProcessing() throws Exception
4037
{

0 commit comments

Comments
 (0)