Hi
The default JSON provider used by the JAXRS implementation is JAXB
based, it does not deal with auto-wrapping of primitive types.
You can register a Jackson JAXRS provider - it should take care of
serializing such types.
Another option is a bit more involved, but would also work, register a
custom JAXRS MessageBodyWriter which would have support all types. It
would have "@Context Providers p;" injected and in its writeTo method it
would either create a JSON representation of the primitive types or
delegate, via the Providers instance to another registered (possibly
default) JSON provider which will manage complex types
Cheers, Sergey
On 26/11/14 19:14, Richard Snowden wrote:
I defined a very simple JAX-RS service with JSON. It works well for complex
data types, but when I use simple types, like boolean or String, I get
malformed JSON data.
...
@POST
@Path("/checkString")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public boolean validate(String myString);
...
In order to get, lets say "someString" in the method validate(), I have to
POST exactly this:
someString
If I post
"someString"
or
{"string" : "someString"}
it won't work (won't de-marshall correctly), because the quotes and
brackets are not removed!
Furthermore the reply of the validate() method is no valid JSON either.
It's simply
true (or false)
But not
"true"
or
{"booleanValue" : "true"}
Does CXF have issues with marshalling/demarshalling simple types correctly
to/from JSON?
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com