Hi
On 15/09/11 22:09, KARR, DAVID wrote:
I had been using Jackson for an earlier service using CXF. I'm now trying to
use the default of Jettison. One thing I'm noticing is that the default output
isn't very efficient wrt output of lists. In the older service, if I had a
list attribute, I would get something like this:
"listprop":[{...firstentry...},{...secondentry...},...]
Now, with Jettison out of the box, I get something like this:
"listprop":{"listtype":[{...firstentry...},{...secondentry...},...]}
You see the addition of the thing that looks like a "listtype". This adds
additional verbosity, which isn't ideal. Is there a straightforward way to optimize this
out?
Jettison may need to be fixed at the code level. I was able to produce
the optimized output after applying a transform feature to JSONPrivider
(indirectly), it may not qualify as a straightforward option :-), but
show the feature can do some fairly 'crazy' transforms :-). So, here is
the original test code:
JSONProvider p = new JSONProvider();
p.setSerializeAsArray(true);
p.setArrayKeys(Arrays.asList(new String[]{"list"}));
// Tags contains a List of Tag objects
Tags tags = new Tags();
tags.addTag(createTag("a", "b"));
tags.addTag(createTag("c", "f"));
// write and capture the output and print which produces:
{"Tags":{"list":[{"group":"b","name":"a"},{"group":"f","name":"c"}]}}
So we have a sub-optimal output with a 'list' wrapper.
The updated test code:
JSONProvider p = new JSONProvider();
// drop top-level Tags
p.setOutDropElements(Arrays.asList(new String[]{"Tags"}));
// rename list to Tags
p.setOutTransformElements(Collections.singletonMap("list", "Tags"));
// Tags contains a List of Tag objects
Tags tags = new Tags();
tags.addTag(createTag("a", "b"));
tags.addTag(createTag("c", "f"));
// write and capture the output and print which produces:
{"Tags":[{"group":"b","name":"a"},{"group":"f","name":"c"}]}
:-)
Cheers, Sergey