Spring MVC: strange @ResponseBody behavior
Hello
I've got hierarchy B extends A. A has property valueA, B has property valueB. Spring MVC example method   
public @ResponseBody A justT开发者_开发知识库esting() {
         return new B();
    }   
JSON answer will be {"valueB":"valueB","valueA":"valueA"}, but I expected {"valueA":"valueA"} because my Interface returns A
Your definition doesn't matter here. The object that is returned is serialized.
You can do either of the following:
- use BeanUtils.copyProperties(..)to copy properties from theBinstance to a newAinstance, specifically created to be returned.
- return new A()
- mark valueBinBas@JsonIgnore
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论