Hi Anthony, Eric,
CC-ing to the users as it can be of interest,
On 02/02/15 13:17, MULLER, Anthony wrote:
Hello again,
About this issue:
2) when there is only one element, we get reports: {report: {name = "foo"}}
--> they'd like: reports: {[report: {name = "foo"}]}
Eric has implemented a solution which consists in scanning our whole JAXB POJO
folder (generated from XSD) and then fill in the serializedAsArray() structure.
It seems to work fine, we need to check it more in details to be sure there is
no regression.
If you can write a code like that then you can write a new Jettison in a
couple of days :-). Nice work Eric
About this second issue, we are a bit stuck:
1) when no element in an array, we get: reports: ""
--> they'd like: reports : [] or reports : null
So, when there is no element, we didn't know how we can configure Jettison to write something different than
"" (empty quote). In most of cases, this behavior is fine (for instance <name></name>
becomes {name : ""}).
However, in some cases, basically when an element can only contain a list of
elements (reports --> report), we're trying to produce something different:
Currently : {reports : ""}
Target output : {reports : null}
Do you see any options we have to do that? We explored some additional settings
introduced into Jettison but we cannot deal with this issue right now...
So you have a 'reports' property as an array key and Jettison reports ""
when a JAXB bean 'reports' property is empty ? Looks like it is a
Jettison bug and needs to be fixed - I'll investigate for Jettison 1.3.7
(in a few weeks realistically).
I think the correct JSON output is actually
"{"reports":[]}"
but if "{reports : null}" is also acceptable then
might be worth experimenting with some of JAXB properties, I guess the
following link can help:
http://blog.bdoughan.com/2012/12/jaxb-representing-null-and-empty.html
You'd probably 'wrap' a given list with XMLElementWrapper and set its
nillable attribute to true, something like that...
In meantime I'll look into making sure Jettison can produce
"{"reports":[]}"
Thanks, Sergey
Thanks again for your help Sergey,
Anthony
-----Original Message-----
From: MULLER, Anthony
Sent: lundi 2 février 2015 11:09
To: 'Sergey Beryozkin'; FESTINGER, Eric
Subject: RE: CXF 2.3.8 + Jackson or Jettison 1.3.7 ?
Thanks for your feedback and various proposal Sergey!
Anthony
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: lundi 2 février 2015 11:05
To: FESTINGER, Eric; MULLER, Anthony
Subject: Re: CXF 2.3.8 + Jackson or Jettison 1.3.7 ?
Hi Eric
Indeed, providing custom XMLStreamWriter or Reader is the most flexible
option to manage various Jettison specific issue. It is a rather complex
approach but it can offer a way to control the process...
Cheers, Sergey
On 02/02/15 07:36, FESTINGER, Eric wrote:
hello Sergey and Anthony,
... and thanks for the explanation about this current patch.
In a meanwhile, I have made some parser which reads our JAXB generated classes,
and populate the xmlStreamWriter.serializeAsArray(...).
Best regards,
eric
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: dimanche 1 février 2015 22:07
To: MULLER, Anthony
Cc: FESTINGER, Eric; [email protected]
Subject: Re: CXF 2.3.8 + Jackson or Jettison 1.3.7 ?
Hi Anthony
I'm CC-ing to the users list because it can be of interest to others.
On 30/01/15 09:35, MULLER, Anthony wrote:
Hello Sergey,
About this issue:
http://jira.codehaus.org/browse/JETTISON-142
Do you think this will help to troubleshoot the array serialization issue with
Jettison?
Not really. JETTISON-142 patch provides a fairly specific work-around
which works only in JSON->XML->JSON auto conversion cases. The challenge
there is to investigate if JSON-> XML or JAXB Bean -> JSON can also
work. Most likely it is not related to the issues you are seeing
In our case, customers provide us several times the same feedback about the
difficulty to handle the JSON output:
1) when no element in an array, we get: reports: ""
--> they'd like: reports : [] or reports : null
2) when there is only one element, we get reports: {report: {name = "foo"}}
--> they'd like: reports: {[report: {name = "foo"}]}
We already know about some existing settings in Jettison (serializedAsArray
flag and this other parameter to provide tag names to deal with), but it is not
flexible enough for us because we have some cases when a tag is effectively in
an array, and another XML document where the same tag name is not in an array...
Jettison 1.3.6 introduces namespace-'local' array keys. For example,
'n1.a', 'n2.b', where 'n1' and 'n2' are namespace prefixes registered in
a separate namespace map.
So, if you have a single JSONProvider handling multiple documents where
an element with a name 'a' is a list in not all of the documents then
most likely you can use something like 'n1.a', etc, to uniquely identify
such a property.
I hope migrating to Jettison 1.3.6 can help. Let me know please
Indeed, Jackson would offer a more robust alternative but you'd need to
annotate the given beans with Jackson annotations...
HTH, Sergey
I'm looking forward to get your point of view.
Best regards,
Anthony
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com