FroMage/jax-doclets — Issue #22: JSON examples should have property names doulble quoted
Author: stanio
Created: 2011-12-23 06:34:30+00:00
State: open

Per JSON specification the property names should be double quoted, otherwise it is invalid JSON syntax. The generated examples are not fully JSON "compatible" but they could be made a bit more useful by making the property name output compliant, anyway.

Proposed patch:

diff --git a/doclets/src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java b/doclets/src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java
--- a/doclets/src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java
+++ b/doclets/src/main/java/com/lunatech/doclets/jax/jaxb/writers/JAXBClassWriter.java
@@ -249,25 +249,25 @@

private void printJSONExample() {
around("b", "JSON Example:");
open("pre");
if(((JAXBConfiguration)configuration).enableJSONTypeName)
- print("{'" + jaxbClass.getName() + "':\n");
+ print("{\"" + jaxbClass.getName() + "\":\n");
print(" {\n");
Collection<Attribute> attributes = jaxbClass.getAttributes();
for (Attribute attribute : attributes) {
- print(" '@");
+ print(" \"@");
around("a href='#m_" + attribute.getName() + "'", attribute.getName());
- print("': ");
+ print("\": ");
printJSONMemberType(attribute, false);
print(",\n");
}
Collection<Element> elements = jaxbClass.getElements();
for (Element element : elements) {
- print(" '");
+ print(" \"");
around("a href='#m_" + element.getName() + "'", element.isWrapped() ? element.getWrapperName() : element.getName());
- print("': ");
+ print("\": ");
printJSONMemberType(element, true);
print(",\n");
}
for (Value value : jaxbClass.getValues()) {
print(" ");