【发布时间】:2016-03-29 20:42:49
【问题描述】:
这里是重要信息。使用泽西岛 1.6。将这种相同类型的列表序列化到前端没有问题,并且不同类型的列表不会在应用程序的其他地方来回导致问题,所以我认为问题出在 bean 本身。我已经尝试过没有额外的路径参数,我遵循所有的 bean 约定,在 ajax 之前数据看起来很好......真的不知道我的问题出在哪里。除了它是一个 NPE 之外,没有真正给出任何信息。
豆子
public class TheBean implements Serializable{
private static final long serialVersionUID = 1L;
private String beanId;
private String name;
private String beanType;
private Boolean group;
public TheBean(){}
public TheBean(String beanId, String name, String beanType, boolean isGroup) {
super();
this.beanId = beanId;
this.name = name;
this.beanType = beanType;
this.group = isGroup;
}
public String getBeanId() {
return beanId;
}
public void setBeanId(String beanId) {
this.beanId = beanId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBeanType() {
return beanType;
}
public void setBeanType(String beanType) {
this.beanType = beanType;
}
public boolean isGroup() {
return group;
}
public void setGroup(boolean group) {
this.group = group;
}
}
网络服务
@POST
@Path("/update/{parentId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response updateTheBeanList(ArrayList<TheBean> routeList, @PathParam("parentId") String parentId){
//code
}
客户端代码
var beanListArray = beanListTable.fnGetData();//looks good here
var json = JSON.stringify(beanListArray);//and here
$.ajax({
dataType: 'text',
type: "POST",
data: json,
url: '${pageContext.request.contextPath}/rest/beanList/update/' + parentId, //looks good here
});
例外
java.lang.NullPointerException
at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findAdapter(JaxbAnnotationIntrospector.java:1058)
at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findDeserializer(JaxbAnnotationIntrospector.java:644)
at org.codehaus.jackson.xc.JaxbAnnotationIntrospector.findDeserializer(JaxbAnnotationIntrospector.java:74)
at org.codehaus.jackson.map.AnnotationIntrospector.findDeserializer(AnnotationIntrospector.java:634)
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findDeserializer(AnnotationIntrospector.java:1286)
有问题的依赖项
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-bundle</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.6</version>
</dependency>
【问题讨论】:
-
奇怪,我假设有以下问题: 1.
@XmlRootElement不存在于TheBean。 2.List<TheBean> routeList而不是ArrayList<TheBean> routeList但我没有得到,为什么你得到NullPointerException- 也许是一个错误,你能更新依赖关系吗? -
我没有用
@XmlRootElement注释任何bean,我在Web 服务的其他地方使用ArrayList没有问题。唯一的区别是额外的路径参数,但我试过没有它。这可能是一个错误,我会修改依赖项。 -
也许可以,但试一试,用 @XmlRootElement 注释 TheBean 并将返回类型更改为 List... 会发生什么?
-
如果这没有改变任何东西...您可以将 maven 依赖项添加到您的问题中...有时会出现与特定组合相关的奇怪事情...
-
是的好主意,OP 用 pom sn-p 更新。
标签: jquery json jersey jackson