@@ -43,6 +43,13 @@ public class XMLParserConfiguration extends ParserConfiguration {
4343 */
4444 private boolean convertNilAttributeToNull ;
4545
46+ /**
47+ * When creating an XML from JSON Object, an empty tag by default will self-close.
48+ * If it has to be closed explicitly, with empty content between start and end tag,
49+ * this flag is to be turned on.
50+ */
51+ private boolean closeEmptyTag ;
52+
4653 /**
4754 * This will allow type conversion for values in XML if xsi:type attribute is defined
4855 */
@@ -145,12 +152,13 @@ public XMLParserConfiguration (final boolean keepStrings, final String cDataTagN
145152 */
146153 private XMLParserConfiguration (final boolean keepStrings , final String cDataTagName ,
147154 final boolean convertNilAttributeToNull , final Map <String , XMLXsiTypeConverter <?>> xsiTypeMap , final Set <String > forceList ,
148- final int maxNestingDepth ) {
155+ final int maxNestingDepth , final boolean closeEmptyTag ) {
149156 super (keepStrings , maxNestingDepth );
150157 this .cDataTagName = cDataTagName ;
151158 this .convertNilAttributeToNull = convertNilAttributeToNull ;
152159 this .xsiTypeMap = Collections .unmodifiableMap (xsiTypeMap );
153160 this .forceList = Collections .unmodifiableSet (forceList );
161+ this .closeEmptyTag = closeEmptyTag ;
154162 }
155163
156164 /**
@@ -169,7 +177,8 @@ protected XMLParserConfiguration clone() {
169177 this .convertNilAttributeToNull ,
170178 this .xsiTypeMap ,
171179 this .forceList ,
172- this .maxNestingDepth
180+ this .maxNestingDepth ,
181+ this .closeEmptyTag
173182 );
174183 }
175184
@@ -303,4 +312,13 @@ public XMLParserConfiguration withForceList(final Set<String> forceList) {
303312 public XMLParserConfiguration withMaxNestingDepth (int maxNestingDepth ) {
304313 return super .withMaxNestingDepth (maxNestingDepth );
305314 }
315+
316+ public XMLParserConfiguration withCloseEmptyTag (boolean closeEmptyTag ){
317+ this .closeEmptyTag = closeEmptyTag ;
318+ return this ;
319+ }
320+
321+ public boolean isCloseEmptyTag () {
322+ return this .closeEmptyTag ;
323+ }
306324}
0 commit comments