0

I am using Enunciate to generate documentation for my REST project. The issue I am having is with the example json object that it generates. While the XML representation is correct, the JSON representation of the same object is missing the root element (in the example below it is "env")

Then Java class defining the object type "env"

@Mapped(namespaceMap = {
        @XmlNsMap(namespace = "http://example.com/myapp", jsonName = "")
})  
@XmlRootElement(name="env")
@XmlAccessorType(XmlAccessType.FIELD)
public  static class Environment {
    public int id;
    public String name;
    public String description;
}

The XML documentation generated by Enunciate (which is correct - root element and all)

<?xml version="1.0" encoding="UTF-8"?> 
<env xmlns="http://example.com/myapp"> 
   <id>...</id> 
   <name>...</name> 
   <description>...</description> 
</env>

The JSON documentation generated by Enunciate (which is incorrect - missing root element "env")

{ 
  "id" : ..., 
  "name" : "...", 
  "description" : "..." 
}

Any help is greatly appreciated.

Rocky
  • 365
  • 1
  • 5
  • 15

1 Answers1

0

There's no such things as a "root" JSON element. How do you expect the "env" property to be in there? The Jackson JSON processor will serialize out that object just like Enunciate is showing as an example. Are you using a different JSON processor?

Ryan Heaton
  • 1,173
  • 7
  • 11
  • When I said "root" element, I meant the root element "env" of the xml. I am using Jettison to serialize. The json output for the example above when using Jettison is {"env" : {"id":..., "name":..., "description":...}}. I understand with Jackson, you can customize the output using the SerializationConfig.Feature.WRAP_ROOT_VALUE option. Did not see a similar option in Jettison – Rocky Apr 12 '14 at 22:44
  • I see. Well, Enunciate assumes the use of Jackson processor, and it's still limited in its custom JSON configuration. So all the examples it generates are going to assume generally what Jackson does by default. – Ryan Heaton Apr 14 '14 at 22:24