File tree Expand file tree Collapse file tree 12 files changed +64
-20
lines changed
main/java/tools/jackson/dataformat/xml
test/java/tools/jackson/dataformat/xml Expand file tree Collapse file tree 12 files changed +64
-20
lines changed Original file line number Diff line number Diff line change 2121 steps :
2222 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2323 - name : Set up JDK
24- uses : actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
24+ uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
2525 with :
2626 distribution : ' temurin'
2727 java-version : ${{ matrix.java_version }}
Original file line number Diff line number Diff line change 2121 with :
2222 ref : 3.x
2323 - name : Set up JDK
24- uses : actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
24+ uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
2525 with :
2626 distribution : ' temurin'
2727 java-version : ${{ matrix.java_version }}
Original file line number Diff line number Diff line change 3030 steps :
3131 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3232 - name : Set up JDK
33- uses : actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
33+ uses : actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1
3434 with :
3535 distribution : ' temurin'
3636 java-version : ${{ matrix.java_version }}
5858 run : ./mvnw -B -q -ff -ntp test
5959 - name : Publish code coverage
6060 if : ${{ matrix.release_build && github.event_name != 'pull_request' }}
61- uses : codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
61+ uses : codecov/codecov-action@ad3126e916f78f00edff4ed0317cf185271ccc2d # v5.4.2
6262 with :
6363 token : ${{ secrets.CODECOV_TOKEN }}
6464 files : ./target/site/jacoco/jacoco.xml
Original file line number Diff line number Diff line change @@ -271,3 +271,8 @@ Bas Passon (@bpasson)
271271* Reported, contributed fix for #646 : Deserializing fails when using builder classes
272272 with `Iterable` Collection setters
273273 (2.17.1 )
274+
275+ 多多冰冰 (@duoduobingbing)
276+
277+ * Contributed #745 : Add feature to include `standalone=' yes' ` in xml declaration
278+ (2.19.0 )
Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ Project: jackson-dataformat-xml
44=== Releases ===
55------------------------------------------------------------------------
66
7- 2.19.0 -rc (07 -Apr-2025 )
7+ #745 : Add feature to include `standalone=' yes' ` in xml declaration
8+ (contributed by @duoduobingbing)
9+
10+ 2.19.0 -rc2 (07 -Apr-2025 )
811
912#700 : Unify testing structure/tools [JSTEP-10 ]
1013 (fix contributed by Joo Hyuk K)
Original file line number Diff line number Diff line change @@ -28,6 +28,13 @@ public enum XmlWriteFeature implements FormatFeature
2828 */
2929 WRITE_XML_1_1 (false ),
3030
31+ /**
32+ * Feature that controls whether XML declaration should include the standalone attribute
33+ * when generator is initialized (true) or not (false). Only honored when
34+ * {@link #WRITE_XML_DECLARATION WRITE_XML_DECLARATION} is enabled
35+ */
36+ WRITE_STANDALONE_YES_TO_XML_DECLARATION (false ),
37+
3138 /**
3239 * Feature that controls whether serialization of Java {@code null} values adds
3340 * XML attribute of `xsi:nil`, as defined by XML Schema (see
Original file line number Diff line number Diff line change 1919import tools .jackson .core .io .NumberInput ;
2020import tools .jackson .core .util .ByteArrayBuilder ;
2121import tools .jackson .core .util .JacksonFeatureSet ;
22- import tools .jackson .dataformat .xml .XmlWriteFeature ;
2322import tools .jackson .dataformat .xml .util .CaseInsensitiveNameSet ;
2423import tools .jackson .dataformat .xml .util .StaxUtil ;
2524
Original file line number Diff line number Diff line change @@ -173,15 +173,23 @@ public void initGenerator() throws JacksonException
173173 _initialized = true ;
174174 try {
175175 boolean xmlDeclWritten ;
176- if (XmlWriteFeature .WRITE_XML_1_1 .enabledIn (_formatFeatures )) {
177- _xmlWriter .writeStartDocument ("UTF-8" , "1.1" );
178- xmlDeclWritten = true ;
179- } else if (XmlWriteFeature .WRITE_XML_DECLARATION .enabledIn (_formatFeatures )) {
180- _xmlWriter .writeStartDocument ("UTF-8" , "1.0" );
176+
177+ if (XmlWriteFeature .WRITE_XML_1_1 .enabledIn (_formatFeatures )
178+ || XmlWriteFeature .WRITE_XML_DECLARATION .enabledIn (_formatFeatures )) {
179+
180+ String xmlVersion = XmlWriteFeature .WRITE_XML_1_1 .enabledIn (_formatFeatures ) ? "1.1" : "1.0" ;
181+ String encoding = "UTF-8" ;
182+
183+ if (XmlWriteFeature .WRITE_STANDALONE_YES_TO_XML_DECLARATION .enabledIn (_formatFeatures )) {
184+ _xmlWriter .writeStartDocument (xmlVersion , encoding , true );
185+ } else {
186+ _xmlWriter .writeStartDocument (encoding , xmlVersion );
187+ }
181188 xmlDeclWritten = true ;
182189 } else {
183190 xmlDeclWritten = false ;
184191 }
192+
185193 // as per [dataformat-xml#172], try adding indentation
186194 if (xmlDeclWritten && (_xmlPrettyPrinter != null )) {
187195 // ... but only if it is likely to succeed:
Original file line number Diff line number Diff line change 88
99import com .ctc .wstx .stax .WstxInputFactory ;
1010import com .ctc .wstx .stax .WstxOutputFactory ;
11+ import com .fasterxml .jackson .annotation .JsonRootName ;
1112
1213import tools .jackson .databind .*;
1314import tools .jackson .dataformat .xml .*;
1415import tools .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
15- import tools .jackson .dataformat .xml .annotation .JacksonXmlRootElement ;
1616
1717import static org .junit .jupiter .api .Assertions .assertNotNull ;
1818
1919// for [dataformat-xml#326]
2020public class FailingNamespace326Test extends XmlTestUtil
2121{
22- @ JacksonXmlRootElement ( localName = "new" )
22+ @ JsonRootName ( "new" )
2323 static class Bean {
2424 @ JacksonXmlProperty (isAttribute = true )
2525 public String source ="ECOM" ;
Original file line number Diff line number Diff line change 88import tools .jackson .dataformat .xml .XmlMapper ;
99import tools .jackson .dataformat .xml .XmlTestUtil ;
1010import tools .jackson .dataformat .xml .annotation .JacksonXmlProperty ;
11- import tools .jackson .dataformat .xml .annotation .JacksonXmlRootElement ;
1211
1312import static org .junit .jupiter .api .Assertions .assertEquals ;
1413import static org .junit .jupiter .api .Assertions .fail ;
@@ -17,7 +16,7 @@ public class TestNamespaces extends XmlTestUtil
1716{
1817 final static String CHILD_NS = "uri:child" ;
1918
20- @ JacksonXmlRootElement ( localName ="person" , namespace ="http://example.org/person" )
19+ @ JsonRootName ( value ="person" , namespace ="http://example.org/person" )
2120 static class Person
2221 {
2322 private String name ;
@@ -63,9 +62,9 @@ static class ChildWithNsJsonProp {
6362 }
6463
6564 /*
66- /**********************************************************
67- /* Unit tests
68- /**********************************************************
65+ /**********************************************************************
66+ /* Test methods
67+ /**********************************************************************
6968 */
7069
7170 private final XmlMapper MAPPER = newMapper ();
You can’t perform that action at this time.
0 commit comments