Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache CXF generates Number instead of String

Tags:

java

jax-rs

cxf

If a string looks like a number, eg. 111 CXF doesn't return it as string, but as number.

<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
    <property name="serializeAsArray" value="true" />
    <property name="arrayKeys" ref="jsonKeys" />
</bean>

As one can see, I use the JSON provider. How can I force it, to deliver correct JSON strings?

{object:{"name":"111"}} instead of {object:{"name":111}}

Thanks in advance...

like image 525
Nabor Avatar asked Nov 28 '25 02:11

Nabor


1 Answers

You can add SimpleConverter to your JSONProvider so that it will not convert strings to numbers. By Default it uses DefaultConverter. But make sure that relevant bean as type string for the field.

<bean id="simpleConverter" class="org.codehaus.jettison.mapped.SimpleConverter"/>

<bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider">
    <property name="typeConverter" ref="simpleConverter"/>
</bean>

You can find more information about this defect in Jettison http://jira.codehaus.org/browse/JETTISON-61 http://jira.codehaus.org/browse/JETTISON-36

like image 95
user1969807 Avatar answered Nov 30 '25 15:11

user1969807



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!