You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Vjacheslav V. Borisov" <sl...@gmail.com> on 2016/04/04 13:56:04 UTC

Dealing with Jettison array serialization issues

Hi!

Looking at

http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison

paragraph "Dealing with Jettison array serialization issues"

does this is only way to configure List<> properties serializtion?


May be there is some undocumented  property to do this transparently,
eg all List<> properties  serialize as array, no matter how many elements
it has (1 or more)

Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2016-05-04 12:59 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:

> On 04/05/16 07:15, Vjacheslav V. Borisov wrote:
>
>>
>> Yes, arrays (lists) serialized correctly, no extra configuration
>> required.
>>
>> I quickly checked the source,
>
>
> http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.persistence/eclipselink/2.5.1/org/eclipse/persistence/jaxb/rs/MOXyJsonProvider.java#MOXyJsonProvider.writeTo%28java.lang.Object%2Cjava.lang.Class%2Cjava.lang.reflect.Type%2Cjava.lang.annotation.Annotation[]%2Corg.eclipse.persistence.jaxb.rs.MediaType%2Corg.eclipse.persistence.jaxb.rs.MultivaluedMap%2Cjava.io.OutputStream%29
>
> Looks like Moxy JAXB Marshaller implementation is explicitly coded to deal
> with either XML or JSON (by passing the properties to it like MediaType,
> etc), which is where it has more control.
>

I  looked too, thinking that there could be possible solution for Jettison,
but MOXyJsonProvider is just wrapper over JAXBContext  marshaller /
unmarshaller

I forget to note that MOXy should be configured as JAXB Provider (actually
we already  using it for it's @XMlInverseReference support and other
features)
http://stackoverflow.com/questions/28676613/set-moxy-as-jaxb-provider-without-properties-file-in-the-same-package/28680795#28680795

Re: Dealing with Jettison array serialization issues

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 04/05/16 07:15, Vjacheslav V. Borisov wrote:
> 2016-05-03 12:01 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
>>
>>
>>> And also copied from AbstractJAXBProvider extraClass and contextProperties
>>> support to custom JaxbContextResolver
>>>
>>> https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/jaxb/JaxbContextResolver.java
>>>
>>> Sure, setting a Moxy ContextResolver should also make CXF JAX-RS
>> providers capable of supporting Moxy JAXB.
>>
>> But does this Moxy provider handle an array serialization issue correctly
>> without the extra arrayKeys config ?
>>
>
> Yes, arrays (lists) serialized correctly, no extra configuration  required.
>
I quickly checked the source,

http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.persistence/eclipselink/2.5.1/org/eclipse/persistence/jaxb/rs/MOXyJsonProvider.java#MOXyJsonProvider.writeTo%28java.lang.Object%2Cjava.lang.Class%2Cjava.lang.reflect.Type%2Cjava.lang.annotation.Annotation[]%2Corg.eclipse.persistence.jaxb.rs.MediaType%2Corg.eclipse.persistence.jaxb.rs.MultivaluedMap%2Cjava.io.OutputStream%29

Looks like Moxy JAXB Marshaller implementation is explicitly coded to 
deal with either XML or JSON (by passing the properties to it like 
MediaType, etc), which is where it has more control.

Sergey


Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2016-05-03 12:01 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:

>
>
>> And also copied from AbstractJAXBProvider extraClass and contextProperties
>> support to custom JaxbContextResolver
>>
>> https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/jaxb/JaxbContextResolver.java
>>
>> Sure, setting a Moxy ContextResolver should also make CXF JAX-RS
> providers capable of supporting Moxy JAXB.
>
> But does this Moxy provider handle an array serialization issue correctly
> without the extra arrayKeys config ?
>

Yes, arrays (lists) serialized correctly, no extra configuration  required.

Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
2016-05-03 12:01 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>

>
>> Actually I have adapted org.eclipse.persistence.jaxb.rs.MOXyJsonProvider
>> to
>> make it more cxf-friendly, e.g to accept SchemaHandler to allow JSON
>> schema
>> validation as Jettison does
>>
>> https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/json/MOXyJsonProvider.java
>>
>> It is still JAXB and XMLSchema in CXF JSONProvider...I believe Jackson
> can handle pure JSON schemas
>

Yes, but we are supporting xml/json interoperation, so we are using xml
schemas.
There is some cases when json benefit (nodejs frontend) and some cases
where xml benefit, e.g. xslt, xsl-fo

Re: Dealing with Jettison array serialization issues

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi


On 01/05/16 20:14, Vjacheslav V. Borisov wrote:
> Started playing with MOXy. I write here in case some else will need to
> switch JSON provider to MOXy.
>
>      <bean id="jsonProvider"
> class="org.eclipse.persistence.jaxb.rs.MOXyJsonProvider">
>          <property name="namespacePrefixMapper" ref="namespaceMap"/>
>          <property name="namespaceSeparator" value=":"/>
>          <property name="formattedOutput" value="true"/>
>          <property name="attributePrefix" value="@"/>
>          <property name="includeRoot" value="true"/>
>          <property name="marshalEmptyCollections" value="false"/>
>      </bean>
> So, if no schema validation or extraClass support required, it is working
> out of box, only need to change property names.
>
Interesting it is nearly a one to one replacement...

>
> Actually I have adapted org.eclipse.persistence.jaxb.rs.MOXyJsonProvider to
> make it more cxf-friendly, e.g to accept SchemaHandler to allow JSON schema
> validation as Jettison does
> https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/json/MOXyJsonProvider.java
>
It is still JAXB and XMLSchema in CXF JSONProvider...I believe Jackson 
can handle pure JSON schemas

>
> And also copied from AbstractJAXBProvider extraClass and contextProperties
> support to custom JaxbContextResolver
> https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/jaxb/JaxbContextResolver.java
>
Sure, setting a Moxy ContextResolver should also make CXF JAX-RS 
providers capable of supporting Moxy JAXB.

But does this Moxy provider handle an array serialization issue 
correctly without the extra arrayKeys config ?

Cheers, Sergey
>
>
> 2016-04-26 17:12 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:
>
>> Thanks, I was  thinking about, but swtiching from jettison is last thing
>> what I wanted to do...
>> Becouse I really loved symmetry in configuring both
>> org.apache.cxf.jaxrs.provider.JAXBElementProvider and
>> org.apache.cxf.jaxrs.provider.json.JSONProvider almost identically
>> and schema validation, and singleJaxbContext, and extraClass...
>>
>> Well, looks like I can use javax.ws.rs.ext.ContextResolver to get similar
>> functionality  like  extraClass.
>> And try to use diffferent JSON provider
>>
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
Started playing with MOXy. I write here in case some else will need to
switch JSON provider to MOXy.

    <bean id="jsonProvider"
class="org.eclipse.persistence.jaxb.rs.MOXyJsonProvider">
        <property name="namespacePrefixMapper" ref="namespaceMap"/>
        <property name="namespaceSeparator" value=":"/>
        <property name="formattedOutput" value="true"/>
        <property name="attributePrefix" value="@"/>
        <property name="includeRoot" value="true"/>
        <property name="marshalEmptyCollections" value="false"/>
    </bean>
So, if no schema validation or extraClass support required, it is working
out of box, only need to change property names.


Actually I have adapted org.eclipse.persistence.jaxb.rs.MOXyJsonProvider to
make it more cxf-friendly, e.g to accept SchemaHandler to allow JSON schema
validation as Jettison does
https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/json/MOXyJsonProvider.java


And also copied from AbstractJAXBProvider extraClass and contextProperties
support to custom JaxbContextResolver
https://github.com/ilb/common/blob/master/common-jaxrs/src/main/java/ru/ilb/common/jaxrs/jaxb/JaxbContextResolver.java



2016-04-26 17:12 GMT+04:00 Vjacheslav V. Borisov <sl...@gmail.com>:

> Thanks, I was  thinking about, but swtiching from jettison is last thing
> what I wanted to do...
> Becouse I really loved symmetry in configuring both
> org.apache.cxf.jaxrs.provider.JAXBElementProvider and
> org.apache.cxf.jaxrs.provider.json.JSONProvider almost identically
> and schema validation, and singleJaxbContext, and extraClass...
>
> Well, looks like I can use javax.ws.rs.ext.ContextResolver to get similar
> functionality  like  extraClass.
> And try to use diffferent JSON provider
>
>

Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
Thanks, I was  thinking about, but swtiching from jettison is last thing
what I wanted to do...
Becouse I really loved symmetry in configuring both
org.apache.cxf.jaxrs.provider.JAXBElementProvider and
org.apache.cxf.jaxrs.provider.json.JSONProvider almost identically
and schema validation, and singleJaxbContext, and extraClass...

Well, looks like I can use javax.ws.rs.ext.ContextResolver to get similar
functionality  like  extraClass.
And try to use diffferent JSON provider


2016-04-26 14:31 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:

> Jettison now supports array keys for specific paths, example, a/b/c
>
> where only a 'c' property of 'b' which is a property of 'c' will be
> treated as an array key.
>
> That said, please do try Jackson, you will use annotations...
>
> Cheers, Sergey
>
>
> On 26/04/16 11:14, Vjacheslav V. Borisov wrote:
>
>> my problem, that same "array key", e.g. "process" could be depending on
>> model single and list value (e.g. one entity contains one-to-one process,
>> second one-to-many process)
>> And specifying globally "process" as arrayKeys is wrong.
>>
>> By googling I found, that such problem has no solution in jettison.
>>
>> 2016-04-25 13:31 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>>
>> The actual serialization work is done by Jettison, CXF JSONProvider only
>>> wraps it and acts as a bridge between JAXB and Jettison.
>>>
>>> Jettison implements XMLStreamWriter and attempts to convert
>>> XMLStreamWriter events into JSON. Thus it needs a configuration support
>>> to
>>> deal with some edge cases...
>>>
>>> Sergey
>>>
>>> On 25/04/16 09:17, Vjacheslav V. Borisov wrote:
>>>
>>> And you don't see possible realisation to automate list property
>>>> identification in case of single list results?
>>>> I don't know well JSONProvider internals, but if you show some glues, i
>>>> might debug/investigate/patch this.
>>>>
>>>> 2016-04-04 16:26 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>>>>
>>>> Hi
>>>>
>>>>>
>>>>> Jettison is XMLStreamWriter, no type information is available.
>>>>> If it does accumulate more than one value for a given property it can
>>>>> guess it must be a list, otherwise it does not know if it is a simple
>>>>> or
>>>>> complex property.
>>>>>
>>>>> Sergey
>>>>>
>>>>>
>>>>> On 04/04/16 12:56, Vjacheslav V. Borisov wrote:
>>>>>
>>>>> Hi!
>>>>>
>>>>>>
>>>>>> Looking at
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison
>>>>>>
>>>>>> paragraph "Dealing with Jettison array serialization issues"
>>>>>>
>>>>>> does this is only way to configure List<> properties serializtion?
>>>>>>
>>>>>>
>>>>>> May be there is some undocumented  property to do this transparently,
>>>>>> eg all List<> properties  serialize as array, no matter how many
>>>>>> elements
>>>>>> it has (1 or more)
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Talend Community Coders
>>> http://coders.talend.com/
>>>
>>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Re: Dealing with Jettison array serialization issues

Posted by Sergey Beryozkin <sb...@gmail.com>.
Jettison now supports array keys for specific paths, example, a/b/c

where only a 'c' property of 'b' which is a property of 'c' will be 
treated as an array key.

That said, please do try Jackson, you will use annotations...

Cheers, Sergey

On 26/04/16 11:14, Vjacheslav V. Borisov wrote:
> my problem, that same "array key", e.g. "process" could be depending on
> model single and list value (e.g. one entity contains one-to-one process,
> second one-to-many process)
> And specifying globally "process" as arrayKeys is wrong.
>
> By googling I found, that such problem has no solution in jettison.
>
> 2016-04-25 13:31 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
>> The actual serialization work is done by Jettison, CXF JSONProvider only
>> wraps it and acts as a bridge between JAXB and Jettison.
>>
>> Jettison implements XMLStreamWriter and attempts to convert
>> XMLStreamWriter events into JSON. Thus it needs a configuration support to
>> deal with some edge cases...
>>
>> Sergey
>>
>> On 25/04/16 09:17, Vjacheslav V. Borisov wrote:
>>
>>> And you don't see possible realisation to automate list property
>>> identification in case of single list results?
>>> I don't know well JSONProvider internals, but if you show some glues, i
>>> might debug/investigate/patch this.
>>>
>>> 2016-04-04 16:26 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>>>
>>> Hi
>>>>
>>>> Jettison is XMLStreamWriter, no type information is available.
>>>> If it does accumulate more than one value for a given property it can
>>>> guess it must be a list, otherwise it does not know if it is a simple or
>>>> complex property.
>>>>
>>>> Sergey
>>>>
>>>>
>>>> On 04/04/16 12:56, Vjacheslav V. Borisov wrote:
>>>>
>>>> Hi!
>>>>>
>>>>> Looking at
>>>>>
>>>>>
>>>>>
>>>>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison
>>>>>
>>>>> paragraph "Dealing with Jettison array serialization issues"
>>>>>
>>>>> does this is only way to configure List<> properties serializtion?
>>>>>
>>>>>
>>>>> May be there is some undocumented  property to do this transparently,
>>>>> eg all List<> properties  serialize as array, no matter how many
>>>>> elements
>>>>> it has (1 or more)
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>> --
>> Sergey Beryozkin
>>
>> Talend Community Coders
>> http://coders.talend.com/
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
my problem, that same "array key", e.g. "process" could be depending on
model single and list value (e.g. one entity contains one-to-one process,
second one-to-many process)
And specifying globally "process" as arrayKeys is wrong.

By googling I found, that such problem has no solution in jettison.

2016-04-25 13:31 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:

> The actual serialization work is done by Jettison, CXF JSONProvider only
> wraps it and acts as a bridge between JAXB and Jettison.
>
> Jettison implements XMLStreamWriter and attempts to convert
> XMLStreamWriter events into JSON. Thus it needs a configuration support to
> deal with some edge cases...
>
> Sergey
>
> On 25/04/16 09:17, Vjacheslav V. Borisov wrote:
>
>> And you don't see possible realisation to automate list property
>> identification in case of single list results?
>> I don't know well JSONProvider internals, but if you show some glues, i
>> might debug/investigate/patch this.
>>
>> 2016-04-04 16:26 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>>
>> Hi
>>>
>>> Jettison is XMLStreamWriter, no type information is available.
>>> If it does accumulate more than one value for a given property it can
>>> guess it must be a list, otherwise it does not know if it is a simple or
>>> complex property.
>>>
>>> Sergey
>>>
>>>
>>> On 04/04/16 12:56, Vjacheslav V. Borisov wrote:
>>>
>>> Hi!
>>>>
>>>> Looking at
>>>>
>>>>
>>>>
>>>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison
>>>>
>>>> paragraph "Dealing with Jettison array serialization issues"
>>>>
>>>> does this is only way to configure List<> properties serializtion?
>>>>
>>>>
>>>> May be there is some undocumented  property to do this transparently,
>>>> eg all List<> properties  serialize as array, no matter how many
>>>> elements
>>>> it has (1 or more)
>>>>
>>>>
>>>>
>>>
>>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>

Re: Dealing with Jettison array serialization issues

Posted by Sergey Beryozkin <sb...@gmail.com>.
The actual serialization work is done by Jettison, CXF JSONProvider only 
wraps it and acts as a bridge between JAXB and Jettison.

Jettison implements XMLStreamWriter and attempts to convert 
XMLStreamWriter events into JSON. Thus it needs a configuration support 
to deal with some edge cases...

Sergey
On 25/04/16 09:17, Vjacheslav V. Borisov wrote:
> And you don't see possible realisation to automate list property
> identification in case of single list results?
> I don't know well JSONProvider internals, but if you show some glues, i
> might debug/investigate/patch this.
>
> 2016-04-04 16:26 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:
>
>> Hi
>>
>> Jettison is XMLStreamWriter, no type information is available.
>> If it does accumulate more than one value for a given property it can
>> guess it must be a list, otherwise it does not know if it is a simple or
>> complex property.
>>
>> Sergey
>>
>>
>> On 04/04/16 12:56, Vjacheslav V. Borisov wrote:
>>
>>> Hi!
>>>
>>> Looking at
>>>
>>>
>>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison
>>>
>>> paragraph "Dealing with Jettison array serialization issues"
>>>
>>> does this is only way to configure List<> properties serializtion?
>>>
>>>
>>> May be there is some undocumented  property to do this transparently,
>>> eg all List<> properties  serialize as array, no matter how many elements
>>> it has (1 or more)
>>>
>>>
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: Dealing with Jettison array serialization issues

Posted by "Vjacheslav V. Borisov" <sl...@gmail.com>.
And you don't see possible realisation to automate list property
identification in case of single list results?
I don't know well JSONProvider internals, but if you show some glues, i
might debug/investigate/patch this.

2016-04-04 16:26 GMT+04:00 Sergey Beryozkin <sb...@gmail.com>:

> Hi
>
> Jettison is XMLStreamWriter, no type information is available.
> If it does accumulate more than one value for a given property it can
> guess it must be a list, otherwise it does not know if it is a simple or
> complex property.
>
> Sergey
>
>
> On 04/04/16 12:56, Vjacheslav V. Borisov wrote:
>
>> Hi!
>>
>> Looking at
>>
>>
>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison
>>
>> paragraph "Dealing with Jettison array serialization issues"
>>
>> does this is only way to configure List<> properties serializtion?
>>
>>
>> May be there is some undocumented  property to do this transparently,
>> eg all List<> properties  serialize as array, no matter how many elements
>> it has (1 or more)
>>
>>
>

Re: Dealing with Jettison array serialization issues

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Jettison is XMLStreamWriter, no type information is available.
If it does accumulate more than one value for a given property it can 
guess it must be a list, otherwise it does not know if it is a simple or 
complex property.

Sergey

On 04/04/16 12:56, Vjacheslav V. Borisov wrote:
> Hi!
>
> Looking at
>
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Jettison
>
> paragraph "Dealing with Jettison array serialization issues"
>
> does this is only way to configure List<> properties serializtion?
>
>
> May be there is some undocumented  property to do this transparently,
> eg all List<> properties  serialize as array, no matter how many elements
> it has (1 or more)
>