Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@xmlns in JSON not showing up when converting to XML #9

Open
mwooten opened this issue May 30, 2019 · 0 comments
Open

@xmlns in JSON not showing up when converting to XML #9

mwooten opened this issue May 30, 2019 · 0 comments

Comments

@mwooten
Copy link

mwooten commented May 30, 2019

It looks like the changes made to the processAttributesAndNamespaces(Node n, JSONObject object) method in the MappedNamespaceConvention.java source back in the 2.0 release, no longer processes no prefix attributes correctly. In the 1.0 release, the following JSON:

{ "toy": { "@xmlns": "http://examples.com" }}

Produced the following XML, when converted:

<toy xmlns="http://examples.com"/>

It no longer does that, starting with the 2.0 release. One possible fix is to add:

if (o instanceof String) {
    String uri = o.toString();
    QName name = new QName( XMLConstants.DEFAULT_NS_PREFIX, k );
    n.setAttribute(name, uri); 
}

after the following if statement:

if ( o instanceof JSONObject ) {
    JSONObject jo = (JSONObject) o;
     for (Iterator<?> pitr = jo.keys(); pitr.hasNext();) {
         // set namespace if one is specified on this attribute.
         String prefix = (String) pitr.next();
         String uri = jo.getString( prefix );
         //                            if ( prefix.equals( "$" ) ) {
         //                                prefix = "";
         //                            }

        n.setNamespace( prefix, uri );
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant