在Sping4.2.8和fastjson1.2.20中,controllr 通过注解ResponseBody无法序列化, 返回{} 也没有报错,尝试其他实体Bean或者List都可以成功序列化
JAVA代码
@RequestMapping(value="/course",method=RequestMethod.GET)
@ResponseBody //将返回的对象 转换成json对象
public ResponseWrapper<List<String>> getCourse(){
List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
return new ResponseWrapper<List<String>>(list,true,"error");
}
public class ResponseWrapper<T> implements Serializable {
private static final long serialVersionUID = 8156927858551514125L;
private final boolean status;
private final String errMsg;
private final T data;
public ResponseWrapper(T data){
this(data,true,"");
}
public ResponseWrapper(T data, boolean status, String errMsg) {
this.data = data;
this.status = status;
this.errMsg = errMsg;
}
}
Spring MVC配置
```
ResponseWrapper 没有getter方法.
Most helpful comment
ResponseWrapper没有getter方法.