You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Massimo Redaelli <ma...@aia.ch> on 2016/05/02 17:08:07 UTC

Jackson converts strings to integers

Hello!

This is probably more of a Jackson question than a CXF question, but if you guys are patient... ^_^

So I didn't like the serialization of one-element lists into objects instead of arrays in Jettison, so I moved to Jackson with:

	<servlet>
		...
		<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
		<init-param>
		  <param-name>jaxrs.providers</param-name>
		  <param-value>
			com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
		  </param-value> 
		</init-param>
	      ...

And that's fixed.

However, I still get that strings like "1234" are serialized to numbers instead of string.

What is the best way of dealing with this? I'd rather not annotate all the string fields with @JsonSerialize(using = ToStringSerializer.class).
(Which I found here: http://stackoverflow.com/questions/16052314/how-can-i-force-jackson-to-write-numbers-as-strings-when-serializing-my-objects )

Can this be done with a global setting? 
Even in my case, without Spring, maybe passing some parameter in the parameter-value element?

Thanks!

Massimo


AW: Jackson converts strings to integers

Posted by Massimo Redaelli <ma...@aia.ch>.
Ehm... never mind.
That happened after the webapplication was only redeployed.
Now I completely restarted tomcat, and lo! the string is a string. I'm a bit puzzled, but oh well, it works :)

Sorry for bothering :/

M.

> -----Ursprüngliche Nachricht-----
> Von: Massimo Redaelli [mailto:massimo.redaelli@aia.ch]
> Gesendet: Montag, 2. Mai 2016 17:08
> An: users@cxf.apache.org
> Betreff: Jackson converts strings to integers
> 
> Hello!
> 
> This is probably more of a Jackson question than a CXF question, but if you
> guys are patient... ^_^
> 
> So I didn't like the serialization of one-element lists into objects instead of
> arrays in Jettison, so I moved to Jackson with:
> 
> 	<servlet>
> 		...
> 		<servlet-
> class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
> 		<init-param>
> 		  <param-name>jaxrs.providers</param-name>
> 		  <param-value>
> 
> 	com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
> 		  </param-value>
> 		</init-param>
> 	      ...
> 
> And that's fixed.
> 
> However, I still get that strings like "1234" are serialized to numbers
> instead of string.
> 
> What is the best way of dealing with this? I'd rather not annotate all the
> string fields with @JsonSerialize(using = ToStringSerializer.class).
> (Which I found here: http://stackoverflow.com/questions/16052314/how-
> can-i-force-jackson-to-write-numbers-as-strings-when-serializing-my-objects
> )
> 
> Can this be done with a global setting?
> Even in my case, without Spring, maybe passing some parameter in the
> parameter-value element?
> 
> Thanks!
> 
> Massimo