gpt4 book ai didi

java - jersey 2.x Moxy json 不支持 POJO 列表

转载 作者:太空宇宙 更新时间:2023-11-04 13:25:27 24 4
gpt4 key购买 nike

我是 Jersey 的新手,当我尝试使用ajax从jquery接收数据到java时,它不映射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

但我想要列出站点对象并将值映射到 POJO,但不起作用。请帮助我,这对我的项目非常有用。谢谢

最佳答案

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

关于java - jersey 2.x Moxy json 不支持 POJO 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32713318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com