Vasantha Raj Vasantha Raj - 6 months ago 55
JSON Question

jersey 2.x Moxy json does not support POJO list

I am new for jersey, while i am trying to receive data from jquery to java using ajax it doesn't map pojo.

POJO :-

@XmlRootElement
public class RulesTO {

private int ruleId;
private String ruleName;
private int ruleStudioId;
private String ruleStudioName;
private String ruleDescription;
private Boolean ruleStatus;
private List<SitesTO> siteRule;
private List<IspsTO> ispRule;
private List<CountriesTO> countryRule;
private String studioDefaultRule;

//getters and setters
}


Ajax :-

var rulesTO = {
ruleName : $('#ruleName').val(),
ruleStudioId : $('#studios option:selected').attr("stream"),
ruleStudioName : $('#studios option:selected').text(),
ruleDescription : $('#ruledescription').val(),
ruleStatus : false,
siteRule : newSiteObject,
ispRule : newIspObject,
countryRule : newCountryObject,
studioDefaultRule : newStudioDefaultObject
}

$.ajax({
url : "/idns/idnsData/saveConfiguration",
type : "POST",
contentType : "application/json",
dataType : "json",
data : JSON.stringify(rulesTO),
success : function(data){
alert("success insert");
}
});


java:-

@Path("/idnsData")
public class IdnsDataHandler {

private static Logger logger = Logger.getLogger(IdnsDataHandler.class);
private Connection connection = null;

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/saveConfiguration")
public RulesTO saveConfiguration(RulesTO rulesTO) throws Exception{
try{
logger.info("IdnsDataHandler : saveConfiguration Method start");
System.out.println("Rule Id : "+rulesTO.getRuleId());
System.out.println("Rule Name : "+rulesTO.getRuleName());
System.out.println("Studio Id : "+rulesTO.getRuleStudioId());
System.out.println("Studio Name : "+rulesTO.getRuleStudioName());
System.out.println("Rule Description : "+rulesTO.getRuleDescription());
System.out.println("Rule Status : "+rulesTO.isRuleStatus());
System.out.println("List Site : "+rulesTO.getSiteRule().size());
System.out.println("List Isp : "+rulesTO.getIspRule().size());
System.out.println("List Country : "+rulesTO.getCountryRule().size());
System.out.println("List studioDefault : "+rulesTO.getStudioDefaultRule());


List<SitesTO> takeall = rulesTO.getSiteRule();
for(int i=0;i<takeall.size();i++){
System.out.println("===="+takeall.get(i).getSiteName());
}
}
}

output :-
Rule Id : 0
Rule Name : example
Studio Id : 3
Studio Name : MAsia
Rule Description : test
Rule Status : false
List Site : 5
List Isp : 0
List Country : 0
List studioDefault : null


but i want List site object and values map to the POJO, but does not work. please kindly help me, this is very useful for my project. thank you

Answer
check the dependencies for Moxy json, Thats work for me.

1.jersey-media-moxy-2.13.jar
2.jersey-entity-filtering-2.13.jar
3.org.eclipse.persistence.antlr-2.5.0.jar
4.org.eclipse.persistence.asm-2.5.0-RC2.jar
5.org.eclipse.persistence.core-2.5.0-RC2.jar
6.org.eclipse.persistence.moxy-2.5.0.jar
Comments