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 theB
instance to a newA
instance, specifically created to be returned. - return
new A()
- mark
valueB
inB
as@JsonIgnore
精彩评论