Fastjson: 嵌套泛型包装类无法自动序列化

Created on 19 Dec 2016  ·  1Comment  ·  Source: alibaba/fastjson

在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配置
```









text/html;charset=UTF-8
application/json







text/plain;charset=UTF-8


question

Most helpful comment

ResponseWrapper 没有getter方法.

>All comments

ResponseWrapper 没有getter方法.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liubailin2017 picture liubailin2017  ·  4Comments

ZYRzyr picture ZYRzyr  ·  3Comments

sd4324530 picture sd4324530  ·  3Comments

Ccixyj picture Ccixyj  ·  4Comments

ITcathyh picture ITcathyh  ·  3Comments