简体   繁体   中英

Is there a class level annotation for @JsonProperty

Is there a class level annotation for jackson 's @JsonProperty ? Without knowing what field names are in the class, I can be able to annotate the class with a annotation and it will map it for me automatically?

Currently I have to annotate each field with a JsonProperty, is there something I can do at the class level that servers the same purpose?

public class myEntity() {

@JsonProperty("banner")
private String banner;

@JsonProperty("menu")
private String menu;

}

@JsonProperty is not class level annotation, and you don't need to mark your class with any annotation. If you provide your class name as an argument to parser it will know how to map it according to your getter methods. It is as if every getter method has been marked with @JsonProperty without any argument

Class level annotation

@JsonRootName("Response")
public class SuperResponse {
...
}

Result:

<Response>
...
</Response>
@JsonRootName(value = "user")
public class User {
public int id;
public String name;
}

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