users@jersey.java.net

[Jersey] Controlling JSON to POJO mapping

From: <carsten_at_byrman.demon.nl>
Date: Tue, 18 Sep 2012 08:58:19 +0000 (GMT)

I am using Jersey's POJO mapping feature to map JSON responses to Java
objects. This works, but I would like to have more control. For
example, consider the following JSON, which uses arrays to minimize the
payload:

{
    "first_names": [
        "Ellen",
        ...
    ],
    "last_names": [
        "Ripley",
        ...
    ]
}

This can easily be mapped to:

public class Persons {

    @JsonProperty("first_names")
    private List<String> firstNames;
    @JsonProperty("last_names")
    private List<String> firstNames;

}

However, I find this inconvenient and ugly. I would rather prefer
somehow a list of Person POJOs, each one having a firstName and
lastName as a String. Is this possible? Should I revert to low-level
JSON support or can this be achieved via the POJO mapping feature?

I have read the Jersey User Guide, but still have no clue on how to do
this. I would be grateful if someone could point me in the right
direction.

Carsten