简体   繁体   中英

Ignore annotation in super class for ObjectMapper

Lets say I have the classes:

public class A {
   @ApiModelProperty(
        hidden = true
    )
  private String text;
  // GET + SET
}


public class B extends A {
  private String name;
  // GET + SET
}

I would like the ObjectMapper NOT to ignore property "text" when creating the JSON of class B

A distinct non-answer: to my knowledge this isn't possible, and also doesn't make sense conceptually.

That annotation is a very explicit mechanism to express a certain semantical meaning.

I assume you are saying: when A objects are serialized, or C objects are serialized (C also extending A, just like B) ... then text should show up. If so: consider using two different base classes then. Because you want to do two different things here. Then make that explicit. Insted of looking for some dirty hack to override that "override" you explicitly put into your code!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM