Use Json root element only for some classes Use Json root element only for some classes json json

Use Json root element only for some classes


Use JsonTypeName with JsonTypeInfo instead of JsonRootName:

@JsonTypeName("user")@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT,use= JsonTypeInfo.Id.NAME)public class User {   ...}

@JsonTypeName

Annotation used for binding logical name that the annotated class has. Used with JsonTypeInfo (and specifically its JsonTypeInfo.use() property) to establish relationship between type names and types.

@JsonTypeInfo

Annotation used for configuring details of if and how type information is used with JSON serialization and deserialization, to preserve information about actual class of Object instances. This is necessarily for polymorphic types, and may also be needed to link abstract declared types and matching concrete implementation.