How to return JSON data from spring Controller using @ResponseBody

后端 未结 8 1085
情深已故
情深已故 2020-11-27 04:55

Spring version 4.2.0, Hibernate 4.1.4 Here is my Controller function:

@RequestMapping(value = \"/mobile/getcomp\", method = Req         


        
8条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 05:41

    You also need to be sure that returned bean is not empty (and can be serialized by Jackson). In my particular case I tried to return an instance of an object without getters and setters and without any jackson annotation and with fields equals to null. I got following message:

    com.fasterxml.jackson.databind.JsonMappingException:
        No serializer found for class com.foo.bar.Baz and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) )
    

提交回复
热议问题