Java : Convert Object consisting enum to Json Object

后端 未结 5 610
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-30 03:13

I am using org.json library to convert Object to Json format. Kindly check the below code snippet.

public enum JobStatus implements Serializable{
     INCOMP         


        
5条回答
  •  误落风尘
    2020-12-30 03:50

    Similar to what @Denys Denysiuk has answered. But if you want to return any value instead of String We can use like this. In below example i wanted to return value 1, or 15 instead of String

    @Getter
    public enum PaymentCollectionDay {
    
        FIRST_OF_MONTH(1), FIFTEENTH_OF_MONTH(15);
        PaymentCollectionDay(int day) {
            this.day = day;
        }
    
        @JsonValue
        final int day;
    }
    

提交回复
热议问题