0

I'm using java, i'm trying to creat a Rest web service,which can to merge a set of return json objects heres the code :

@Path("/all/{profileId}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response all(@PathParam("profileId") String profileId) {
    Response profile = null;
    Response cards = null;
    Response childs= null;
    Response returnValue = null;

    try {
        ProfilJson profilJson = profilBean.getProfil(profileId);
        List<LoyaltyCardJson> listLoyaltyCardsJson = loyaltyCardBean.getcards(profileId);
        List<LoyaltyChildJson> listLoyaltyChildsJson = loyaltyCardBean.getChildd(profileId);

        if (profilJson != null) {
            profile = JsonResponse.objectToJson(profilJson);
            cards = JsonResponse.objectToJson(listLoyaltyCardsJson);    
            childs = JsonResponse.objectToJson(listLoyaltychildsJson);
        } else {
            returnValue = JsonResponse.noDataToReturn();
        }
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);

    }
    return   returnValue;
}

i give you an exemple of the returned objects :

profile = [{name: "Mary", car: "Fiat"}];

cards= [{firstName: "Mack", lastName: "jack"},{firstName: "Steve", lastName: "martin"}];

childs= [{firstName: "toto", lastName: "jack"},{firstName: "titi", lastName: "martin"}];

what i want to do is, to generate a global object which i can put it into the returnValue variable, and this object must like :

[{"name": "Bob", "car": "Ford", "cards":[{"Name": "Mack", "Type": "jack"},{"Name": "Steve","TypeName": "martin"},...], "childs":[{"firstName": "toto", "lastName": "jack"},{"firstName": "titi", "lastName": "martin"},...] }]

P.S cards and childs objects contain a list of objects, i gave two objects to each one in this exemple just help you to understand the problem.

0 Answers0