The server encountered an internal error that prevented it from fulfilling this request.(JsonMappingException: Conflicting getter definitions)
在测试一个方法,dubug查看查询结果已经出来了,结果页面上是The server encountered an internal error that prevented it from fulfilling this request.,再debug ,发现ServletInvocableHandlerMethod#invokeAndHandle中 发现如下异常:
org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Conflicting getter definitions for property "buyNow":..........nested exception is org.codehaus.jackson.map.JsonMappingException: Conflicting getter definitions for property "buyNow".....xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx#isBuyNow(0 params) vs xxxxxxxxxxxxxxxx#getBuyNow(0 params)
从上面的异常找到相应的bean,如下图3行和11行
1 /** 是否直接购买(1|是,0|不是,默认0) */ 2 private Integer buyNow; 3 public Integer getBuyNow (){ 4 return buyNow; 5 } 6 7 public void setBuyNow (Integer buyNow){ 8 this.buyNow = buyNow; 9 } 10 11 public boolean isBuyNow() { 12 return BUY_NOW_YES.equals(buyNow); 13 }
从异常提示的信息可以看出jackson处理bean时不知道该调用#isBuyNow还是#getBuyNow,对于此次当然可以告诉jackson忽略,加个@JsonIgnore是可以的,但是这个地方其实平时代码规范的问题,其实不仅是jackson处理上还有其它的地方也会有此问题,所以方法命名上就要杜绝这种is打头的命名方式是最好的(我认为的)。
,