Skip to content

Commit

Permalink
Fix for @xmlns (without namespace prefix) not appearing as xmlns attr…
Browse files Browse the repository at this point in the history
…ibute when generating XML from JSON
  • Loading branch information
mwooten authored and dkulp committed Dec 12, 2019
1 parent d80e945 commit 1610e84
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,25 @@ public void processAttributesAndNamespaces( Node n, JSONObject object ) throws J
n.setNamespace( prefix, uri );
}
}
// With the 1.0 release, the default behavior was to treat an @xmlns
// JSON field name (without a namespace prefix), as the attribute for
// the default namespace URI. During JSON->XML serialization, this
// default behavior resulted in an xmlns (without a namespace prefix)
// attribute appearing on the applicable element, with the default
// namespace uri as it's value.
//
// The code refactoring in this processAttributesAndNamespaces
// method back in the 2.0 release, no longer assigns the default
// namespace URI to the xmlns (without a namespace prefix) during JSON->XML
// serialization, which in some cases is causing unmarshaling issues.
// Putting in the following conditional check, restores the previous
// default behavior, without breaking anything added during the earlier
// refactoring exercise.
if (o instanceof String) {
String uri = o.toString();
QName name = new QName( XMLConstants.DEFAULT_NS_PREFIX, k);
n.setAttribute(name, uri);
}
}
else {
String strValue = o == null ? null : o.toString();
Expand Down

0 comments on commit 1610e84

Please sign in to comment.