Jettison and JAXB automatically change data type in JSON Response

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

+4
source share
2 answers

This seems to be an implicit "feature" of Jettison; he is trying to research the evidence and figure out which best type is right. I have come across this before, and it infuriates.

I highly recommend turning Jettison off completely and using RestEasy Jackson instead. Jackson is a much better library and does not suffer from these “useful” features. It also supports JAXB annotations , as does Jettison.

+4
source

You have a listner that sets the system property below when the server starts.

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

After the property is set to simpleConverter , then jettison always displays the values ​​as a string, regardless of whether the data type is a string or int.

0
source

Source: https://habr.com/ru/post/1336389/


All Articles