Home > Back-end >  Spring how json serialization and parsing enum data?
Spring how json serialization and parsing enum data?

Time:03-02


 
@ Getter
@ AllArgsConstructor
@ JsonDeserialize (using=EnumDeserializer. Class)
@ JsonSerialize (using=EnumSerializer. Class)
Enum HttpResult {
Success (200, "Success"),//pay attention to the comma
Failed (500, "Failed");//note that semicolon

private int code;
Private String status;
}


This configuration complains
 
The Exception in the thread "main" com. Fasterxml. Jackson. Databind. JsonMappingException: Class com. Fasterxml. Jackson. Databind. Ser. STD. EnumSerializer has no default (no arg) constructor


Hope to get the
{" code ": 500, the" status ":" Failed "} so that the output of the

Could you tell me how to realize the enum Jackson json serialization and deserialization

CodePudding user response:

@ NoArgsConstructor class upon this

CodePudding user response:

Json data conversion usually use ordinary objects instead of enum

CodePudding user response:

reference 1st floor lkwahl response:
@ NoArgsConstructor class and add the

No is still the same error

CodePudding user response:

Why must is enumerated? The enumeration of the information out into the object, and the operation is simple

CodePudding user response:

Why must is enumerated? The enumeration of the information out into the object, and the operation is simple

CodePudding user response:

reference 5 floor a1767028198 reply:
why must be enumerated? Throwing the enumeration information out to the object, the operation is simple much

If so I can direct serial number deserialization enum is not a simple
As a whole is to how to assign a value analysis can also automatically accomplish this
  • Related