JAXB is an API for XML, not JSON.
However, there are some JSON libraries (at least Jackson) which can utilize JAXB annotations. I don't know which one you are using, so I don't know exactly how to best help. (If you are using this with the Jersey framework, it uses Jackson for its JSON serialization.) You will need to configure whatever JSON library you are using to be able to configure the "wrapping" of the root element in the JSON output.
I wrote up this quick Groovy script to test this in Jackson:
@Grab('com.fasterxml.jackson.core:jackson-databind:2.2.2')
import javax.xml.bind.annotation.XmlRootElement
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
@XmlRootElement
public class Person {
public String desc = "howdy"
}
Person p = new Person()
ObjectMapper om = new ObjectMapper().enable(SerializationFeature.WRAP_ROOT_VALUE)
println om.writeValueAsString(p)
As it is written above, it outputs the JSON:
{"Person":{"desc":"howdy"}}
If you take out the part .enable(SerializationFeature.WRAP_ROOT_VALUE)
it gives you:
{"desc":"howdy"}
So if you are using Jackson, it looks like the ObjectMapper that is being used behind the scenes is being set to WRAP_ROOT_VALUE
and you just need to turn that off.