Spring MVC and Jackson mapping do not return the root element in json

后端 未结 4 1917
夕颜
夕颜 2021-01-06 12:09

I am having one issue with Spring MVC and its json support. I make one ajax call to get some data and I want to get that data in json format including the root value. I am

4条回答
  •  逝去的感伤
    2021-01-06 12:32

    Wrap your "Issuers" in a generic holder-object. That's what I do when working with Jackson and Spring.

    class JSONResponse {
    
        private Object collection;
    
        public JSONResponse(Object collection) {
            this.collection = collection;
        }
        public Object getCollection() {
            return collection;
        }
    }
    

    ...

    @RequestMappin(...)
    @ResponseBody
    public Object someHandler(...) {
        ...
        return new JSONResponse(issuers);
    }
    

提交回复
热议问题