@@ -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 */
@@ -142,15 +149,17 @@ public XMLParserConfiguration (final boolean keepStrings, final String cDataTagN
142149 * xsi:type="integer" as integer, xsi:type="string" as string
143150 * @param forceList <code>new HashSet<String>()</code> to parse the provided tags' values as arrays
144151 * @param maxNestingDepth <code>int</code> to limit the nesting depth
152+ * @param closeEmptyTag <code>boolean</code> to turn on explicit end tag for tag with empty value
145153 */
146154 private XMLParserConfiguration (final boolean keepStrings , final String cDataTagName ,
147155 final boolean convertNilAttributeToNull , final Map <String , XMLXsiTypeConverter <?>> xsiTypeMap , final Set <String > forceList ,
148- final int maxNestingDepth ) {
156+ final int maxNestingDepth , final boolean closeEmptyTag ) {
149157 super (keepStrings , maxNestingDepth );
150158 this .cDataTagName = cDataTagName ;
151159 this .convertNilAttributeToNull = convertNilAttributeToNull ;
152160 this .xsiTypeMap = Collections .unmodifiableMap (xsiTypeMap );
153161 this .forceList = Collections .unmodifiableSet (forceList );
162+ this .closeEmptyTag = closeEmptyTag ;
154163 }
155164
156165 /**
@@ -169,7 +178,8 @@ protected XMLParserConfiguration clone() {
169178 this .convertNilAttributeToNull ,
170179 this .xsiTypeMap ,
171180 this .forceList ,
172- this .maxNestingDepth
181+ this .maxNestingDepth ,
182+ this .closeEmptyTag
173183 );
174184 }
175185
@@ -303,4 +313,19 @@ public XMLParserConfiguration withForceList(final Set<String> forceList) {
303313 public XMLParserConfiguration withMaxNestingDepth (int maxNestingDepth ) {
304314 return super .withMaxNestingDepth (maxNestingDepth );
305315 }
316+
317+ /**
318+ * To enable explicit end tag with empty value.
319+ * @param closeEmptyTag
320+ * @return same instance of configuration with empty tag config updated
321+ */
322+ public XMLParserConfiguration withCloseEmptyTag (boolean closeEmptyTag ){
323+ XMLParserConfiguration clonedConfiguration = this .clone ();
324+ clonedConfiguration .closeEmptyTag = closeEmptyTag ;
325+ return clonedConfiguration ;
326+ }
327+
328+ public boolean isCloseEmptyTag () {
329+ return this .closeEmptyTag ;
330+ }
306331}
0 commit comments