Closed stanio closed 12 years ago
Good idea.
Need this change as well.
but, is there any case, in which pre>@</pre is needed in attribute name in JSON example ? probably, it would be enough to remove pre>@</pre printing in JSON example. patch JAXBClassWriter.printJSONExample was:
print(" \"@");
become:
print(" \"");
It depends on your JSON marshaller. In RESTEasy the default is to get @
.
ok. I'm not sure if the fix is enough.
if ("-disablejaxbmethodoutput".equals(option) || "-disablejsontypename".equals(option) || "-disablexmlexample".equals(option) || "-disablejsonexample".equals(option) return 1; }
become
if ("-disablejaxbmethodoutput".equals(option) || "-disablejsontypename".equals(option) || "-disablexmlexample".equals(option) || "-disablejsonexample".equals(option) || "-useplainjsonattributenames".equals(option)) { return 1; }
2.JAXBConfiguration 2.1. Add variable
public boolean useJSONPlainAttribute = false;
2.2. At the end of the function setOptions add code
useJSONPlainAttribute = Utils.hasOption(options, "-useplainjsonattributenames");
3.JAXBClassWriter.printJSONExample in the loop by attributes was:
print(" \"@");
become:
print(" \""); if(!((JAXBConfiguration) configuration).useJSONPlainAttribute) print("@");
Just for information, the requested behavior matches what's called Natural JSON notation:
http://jersey.java.net/nonav/documentation/latest/json.html#d4e1058
There appear also Mapped, Jettison-mapped and Badgerfish notations:
http://jersey.java.net/nonav/documentation/latest/json.html#d4e949
These could be used like -jsonnotaton natural
in future to switch between whole different behavior, if implemented.
Done with -jsonconvention mapped
in latest git.
Jackson supports mapping Java Beans to/from JSON using JAXB annotations:
http://wiki.fasterxml.com/JacksonJAXBAnnotations
Its mapping is really simple and doesn't try to distinguish XML features like attributes (vs. elements) and namespaces, so both of the following two versions:
and:
get serialized as:
and not as:
It would be nice if there's an option to omit the code>@</code in attribute names in the generated JSON examples, e.g.
-useplainjsonattributenames
, though this is a bit lengthy one.