3

I have the following class....

@XmlType
@XmlRootElement(name = "milestones")
@XmlAccessorType(XmlAccessType.FIELD)
public static class Circle {
    public String type = "circle";
    public double cx;
    public double cy;
    public int r;
    public String title;
    public Integer width;   
}

I am returning a List of Circles (actually using JaxRS with RestEasy, which uses Jackson)

I want the Json output to be like

[{"type":"circle","cx":100.0,"cy":100.0,"r":0,"title":"test1","width":2},
{"type":"circle","cx":150.0,"cy":150.0,"r":0,"title":"test2","width":0}]

and on my dev machine that is how the output looks, but on production it is like

[{"milestones":{"type":"circle","cx":100,"cy":100,"r":0,"title":"test1","width":2}}, 
{"milestones":{"type":"circle","cx":150,"cy":150,"r":0,"title":"test2","width":0}}]

Is there a way to force it to use the first output format (without the name listed)?

Thanks for your help, Mason

kaiz.net
  • 1,984
  • 3
  • 23
  • 31

1 Answers1

0

With the same codebase its highly unlikely that the outputs are different on the two machines.

This behaviour is driven by the WRAP_ROOT_VALUE feature of the ObjectMapper, so you might want to try turning it explicitly off using the code below (you might also want to check if it is being exlicitly turned on somewhere in your code, as by default this feature is disabled)

mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false);

Since you are using RestEasy, you will need to extend the RestEasyJacksonProvider to get access to the underlying ObjectMapper.

gresdiplitude
  • 1,665
  • 1
  • 15
  • 27
  • Thank you very much. I went ahead and manually created the JSON as a string, but hopefully this will help someone else, or me in the future. – user1461057 Jun 18 '12 at 23:07