On Tue, Sep 18, 2012 at 2:58 PM, Carsten Byrman <carsten_at_byrman.demon.nl> wrote:
> On 09/18/2012 07:33 PM, Tatu Saloranta wrote:
>>
>> On Tue, Sep 18, 2012 at 5:46 AM, Carsten Byrman <carsten_at_byrman.demon.nl>
>> wrote:
>>>
>>> Thanks for your time, Mike.
>>>
>>> So 5.2 of the Jersey User Guide (JAXB Based JSON support) is the way to
>>> go -
>>> even if the web service only returns JSON (no XML)?
>>
>> Example given did not actually use any of JAXB, not even annotations,
>> so it's bit of a red herring.
>> Structure given works as-is with Jackson-based POJO-mapping.
>>
>> -+ Tatu +-
>
> Thanks for your help as well, Tatu.
>
> I am still a bit confused. Let me try to summarize. The web service only
> returns JSON. I do not have control over the JSON format. To minimize the
> payload, it returns arrays of strings (first_names, last_names). I am able
> to map this using Jersey's POJO mapping feature, but I do not like the
> corresponding Java class. I would rather prefer a List<Person>.
Ah. No, this kind of structural transformations are not supported by
Jackson or other data-binding libraries I am familiar with
Jackson does have a limited set of structural transformers for basic
wrapping/unwrapping cases, but that's it.
You will need to handle this semi-automatically: possibly doing
partial data-binding (`JsonNode` is the type that can be used to get
JSON Tree values; and ObjectMapper can convert between POJOs and
JsonNodes seamlessly and relatively efficiently).
The structure in use definitely seems like Bad Design, perhaps due to
pre-mature optimization attempt. Or maybe due to inexperience by
whoever cobbled it together. I wish this was not a common occurence,
but I see it all the time. :-/
-+ Tatu +-