users@jersey.java.net

[Jersey] How to populate nested object from JSON data.

From: joey.lv <joey.lv_at_7road.com>
Date: Fri, 31 Oct 2014 15:37:50 +0800

Jersey version: 2.13
JSON support: moxjersey-media-moxy y

JSON data:
{
    "agentName": "myAgent",
    "gameId": 2,
    "id": 1,
    "loginName": "admin",
    "userAgentDetailList": [
        {
            "agentId": "agent_1"
        },
        {
            "agentId": "agent_2"
        },
        {
            "agentId": "agent_3"
        }
    ]
}

UserAgent.java
@XmlRootElement
public class UserAgent implements Serializable {
    private Integer id;

    private String loginName;

    private Integer gameId;

    private String agentName;

    List<UserAgentDetail> userAgentDetailList;

    //setter,getter
}



UserAgentDetail.java
@XmlRootElement
public class UserAgentDetail implements Serializable {
    private Integer id;

    private Integer userAgentId;

    private String agentId;
    ...

    //setter,getter
}



UserAgentResource.java
@PUT
@Produces("application/json;charset=UTF-8")
@Consumes("application/json")
public String putUserAgent(UserAgent userAgent) {
    logger.entry();
    //do something...
    logger.exit();
    return "";
}


I found the useAgent is auto populated correctly,
but the nested List<UserAgentDetail> userAgentDetailList, could not be populated correctly, actually, the List is created, but the elements in the List are not created properly.


so, how to process the nested object?
thanks.



Catch.jpg
(image/jpeg attachment: Catch.jpg)