4

I'm using Resteasy 2.0.1.GA and Resteasy-jettison-provider-1.2.GA with JAXB annontations and whenever I have a String property that contains all numbers (i.e. String groupName="1111";), the JSON response will display it as a number by removing the double quotes. If I change it to String groupName="oneoneoneoneone"; the JSON response will treat it as a Sting and keep the double quotes in the response. Is there anyway to have the Jettison provider strictly interpret the data to response based on its type and not its value?

skaffman
  • 398,947
  • 96
  • 818
  • 769
colin gray
  • 51
  • 1
  • 5

2 Answers2

4

This seems to be an implicit "feature" of Jettison; it tries to introspect the actual data and figure out what's the best type fit. I've come across it before, and it's infuriating.

I strongly recommend ditching Jettison completely, and using the RestEasy Jackson support instead. Jackson is a much better quality library, and doesn't suffer from these "helpful" features. It also supports JAXB annotations just like Jettison.

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • Thanks for the response. I've tried out Jackson but the problem is that its a major rewrite for us since we're so dependent on our JAXB annotations. Do you know of a way around this besides switching providers? – colin gray Jan 20 '11 at 22:38
  • 1
    @Colin: I just said that Jackson supports JAXB annotations as well. – skaffman Jan 20 '11 at 22:38
  • Skaffman, I've tried registering a JAXB annotation introspector following the spec (http://wiki.fasterxml.com/JacksonJAXBAnnotations) but I don't see how to dynamically plug that into my restful framework (RESTEasy). How can you register it in such a way that it gets called during the serialization of the response object? Its definitely a knowledge gap on my side, but I can't find much help regarding the integration. – colin gray Jan 20 '11 at 23:18
  • @Colin: My neither, I'm afraid, I don't use resteasy. You might want to try the mailing list for one or both of them. – skaffman Jan 20 '11 at 23:23
0

Have listner which sets the below system property when server starts.

System.setProperty("jettison.mapped.typeconverter.class"
                  ,"org.codehaus.jettison.mapped.SimpleConverter");

Once the property is set to simpleConverter then jettison output the values always as string whether the data type is string or int does not matter.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Narendra Reddy
  • 358
  • 2
  • 6