Serializing enums with Jackson

后端 未结 7 1371
借酒劲吻你
借酒劲吻你 2020-11-28 01:50

I have an Enum desrcibed below:

public enum OrderType {

  UNKNOWN(0, \"Undefined\"),
  TYPEA(1, \"Type A\"),
  TYPEB(2, \"Type B\"),
  TYPEC(3, \"Type C\");         


        
7条回答
  •  情书的邮戳
    2020-11-28 02:16

    In Spring Boot 2, the easiest way is to declare in your application.properties:

    spring.jackson.serialization.WRITE_ENUMS_USING_TO_STRING=true
    spring.jackson.deserialization.READ_ENUMS_USING_TO_STRING=true
    

    and define the toString() method of your enums.

提交回复
热议问题