Skip to content

Commit ea62556

Browse files
committed
Add new ElementWrappable marker interface
1 parent aff78c0 commit ea62556

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fasterxml.jackson.dataformat.xml.deser;
2+
3+
import java.util.Set;
4+
5+
/**
6+
* Minimal API to be implemented by XML-backed parsers for which "virtual"
7+
* wrapping may be imposed.
8+
*<p>
9+
* NOTE: this method is considered part of internal implementation
10+
* interface, and it is <b>NOT</b> guaranteed to remain unchanged
11+
* between minor versions (it is however expected not to change in
12+
* patch versions). So if you have to use it, be prepared for
13+
* possible additional work.
14+
*
15+
* @since 2.15
16+
*/
17+
public interface ElementWrappable
18+
{
19+
/**
20+
* Method that may be called to indicate that specified names
21+
* (only local parts retained currently: this may be changed in
22+
* future) should be considered "auto-wrapping", meaning that
23+
* they will be doubled to contain two opening elements, two
24+
* matching closing elements. This is needed for supporting
25+
* handling of so-called "unwrapped" array types, something
26+
* XML mappings like JAXB often use.
27+
*/
28+
public void addVirtualWrapping(Set<String> namesToWrap0, boolean caseInsensitive);
29+
}

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
public class FromXmlParser
3131
extends ParserMinimalBase
32+
implements ElementWrappable // @since 2.15
3233
{
3334
/**
3435
* The default name placeholder for XML text segments is empty
@@ -431,27 +432,11 @@ public XMLStreamReader getStaxReader() {
431432

432433
/*
433434
/**********************************************************
434-
/* Internal API
435+
/* ElementWrappable implementation
435436
/**********************************************************
436437
*/
437438

438-
/**
439-
* Method that may be called to indicate that specified names
440-
* (only local parts retained currently: this may be changed in
441-
* future) should be considered "auto-wrapping", meaning that
442-
* they will be doubled to contain two opening elements, two
443-
* matching closing elements. This is needed for supporting
444-
* handling of so-called "unwrapped" array types, something
445-
* XML mappings like JAXB often use.
446-
*<p>
447-
* NOTE: this method is considered part of internal implementation
448-
* interface, and it is <b>NOT</b> guaranteed to remain unchanged
449-
* between minor versions (it is however expected not to change in
450-
* patch versions). So if you have to use it, be prepared for
451-
* possible additional work.
452-
*
453-
* @since 2.12
454-
*/
439+
@Override
455440
public void addVirtualWrapping(Set<String> namesToWrap0, boolean caseInsensitive)
456441
{
457442
//System.out.printf("addVirtualWrapping(%s) at '%s' [case-insensitive? %s]\n", namesToWrap0, _parsingContext.pathAsPointer(), caseInsensitive);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected final void _configureParser(JsonParser p) throws IOException
154154
while (p instanceof JsonParserDelegate) {
155155
p = ((JsonParserDelegate) p).delegate();
156156
}
157-
if ((p instanceof FromXmlParser) && (_namesToWrap != null)) {
157+
if ((p instanceof ElementWrappable) && (_namesToWrap != null)) {
158158
// 03-May-2021, tatu: as per [dataformat-xml#469] there are special
159159
// cases where we get String token to represent XML empty element.
160160
// If so, need to refrain from adding wrapping as that would
@@ -166,7 +166,7 @@ protected final void _configureParser(JsonParser p) throws IOException
166166
// is consumed during buffering, so need to consider that too
167167
// it seems (just hope we are at correct level and not off by one...)
168168
|| t == JsonToken.FIELD_NAME) {
169-
((FromXmlParser) p).addVirtualWrapping(_namesToWrap, _caseInsensitive);
169+
((ElementWrappable) p).addVirtualWrapping(_namesToWrap, _caseInsensitive);
170170
}
171171
}
172172
}

0 commit comments

Comments
 (0)