Could not write JSON document: (was java.lang.NullPointerException) (through reference chain
2017-11-20 14:42
676 查看
刚刚测试提了个bug查询错误,就找了下,原因是json问题吧,看看报的错,看了看bean也没啥问题。后面找一下了;看到一个大哥说的恍然。。。原来是一个坑。
在项目中,我们都会建model包下的实体bean。每个实体的属性的数据类型可能用了基本类型;也可能用了包装类型,可能有时候在处理业务的时候null值的处理方式我们直接修改bean的字段类型为但是又没有把setter/getter方法重新生成,就比如我的一个字段类型仅仅把属性的基本类型(如double)改为包装类型(如Double),而并没有将setter/getter的类型一起修改。
这种情况会报错,而且报的错经常会让人摸不着头脑。下面列举了一种情况,是利用com.fasterxml.jackson将Entity序列化为Json字符串时出现上述疏忽报的错误:
com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference
我的bean:
private Double receiveDis;
public double getReceiveDis() {
return receiveDis;
}
public void setReceiveDis(double receiveDis) {
this.receiveDis = receiveDis;
}
这个坑入得还真有点深。记录一下;希望大家注意了。
在项目中,我们都会建model包下的实体bean。每个实体的属性的数据类型可能用了基本类型;也可能用了包装类型,可能有时候在处理业务的时候null值的处理方式我们直接修改bean的字段类型为但是又没有把setter/getter方法重新生成,就比如我的一个字段类型仅仅把属性的基本类型(如double)改为包装类型(如Double),而并没有将setter/getter的类型一起修改。
这种情况会报错,而且报的错经常会让人摸不着头脑。下面列举了一种情况,是利用com.fasterxml.jackson将Entity序列化为Json字符串时出现上述疏忽报的错误:
com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference
我的bean:
private Double receiveDis;
public double getReceiveDis() {
return receiveDis;
}
public void setReceiveDis(double receiveDis) {
this.receiveDis = receiveDis;
}
这个坑入得还真有点深。记录一下;希望大家注意了。
相关文章推荐
- Could not write JSON document: (was java.lang.NullPointerException) (through reference chain
- 自己挖坑自己跳 之JsonMappingException: (was java.lang.NullPointerException) (through reference chain:)
- Could not publish to the server. java.lang.NullPointerException
- Could not publish to the server. java.lang.NullPointerException
- Could not open JPA EntityManager for transaction; nested exception is java.lang.NullPointerException
- Could not write JSON: Infinite recursion (StackOverflowError) (through reference chain:
- Tomcat启动报Could not publish to the server. java.lang.NullPointerException
- 使用myeclipse启动tomcat时出现这种错误“Could not publish to the server. java.lang.NullPointerException”
- Could not publish to the server.java.lang.NullPointerException
- Provider null could not be instantiated: java.lang.NullPointerException
- Could not write JSON: Infinite recursion (StackOverflowError) (through reference chain:
- Could not clean server of obsolete files: null java.lang.NullPointerException
- Tomcat服务器报错: Could not publish to the server. java.lang.NullPointerException
- Could not publish to the server. java.lang.NullPointerException
- JsonMappingException: (was java.lang.NullPointerException)
- Could not publish to the server. java.lang.NullPointerException
- Could not publish to the server. Java.lang.NullPointerException
- Could not publish to the server. java.lang.NullPointerException
- 解决Could not write JSON: Infinite recursion (StackOverflowError) (through reference chain