tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject Re: Dealing with Jettison array serialization issues
Date Wed, 05 Feb 2014 11:25:03 GMT
Hi

we had a *user* issue to exactly ask the opposite (TOMEE-514, it was
consistent IMHO). The idea is to rely on cxf behavior by default as
much as possible.

That said you don't need to write your custom provider, just define it
in openejb-jar.xml and resources.xml:
http://openejb.979440.n4.nabble.com/Configuring-Apache-CXF-in-TomEE-td4660207.html

Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014-02-05 Johnny Macnum <johnny_macnum@hotmail.com>:
> Hello,
>
> As described in the CXF document (http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-ConfiguringJSONprovider),
Jettison wrongly serializes List objects by default. The default approach of Jettison is for
me a bad practice.
>
> JSONProvider has two properties 'serializeAsArray'  and 'arrayKeys' to handle this issue.
>
>
> I think TomEE initializes wrongly the JSONProvider. You should by default set serializeAsArray
to 'true' and allow the developer to configure the list of keys to put in the arrayKeys so
as to produce a well-defined JSON.
>
>  private static List<Object> defaultProviders() {
>         final JAXBElementProvider jaxb = new JAXBElementProvider();
>         final Map<String, Object> jaxbProperties = new HashMap<String, Object>
();
>         jaxbProperties.put(Marshaller.JAXB_FRAGMENT, true);
>         jaxb.setMarshallerProperties(jaxbProperties);
>
>         final JSONProvider json = new JSONProvider();
>         // TOMEE-514
>         // json.setSerializeAsArray(true);
>
>         return Arrays.asList((Object) jaxb, json);
>     }
>
> In order to solve my issue, I had to define my customer provider which is quite cumbersome
for a lambda developer.
>
> @Produces("application/json")
> @Consumes("application/json")
> @Provider
> public class CustomJSONProvider<T> extends JSONProvider<T> {
>
>     public CustomJSONProvider() {
>         super();
>         setSerializeAsArray(true);
>         setArrayKeys(Arrays.asList("element1", "element2"));
>     }
>
> }
>
>
> Regards,
>
> Jonathan
>
>

Mime
View raw message