Java : Convert Object consisting enum to Json Object

后端 未结 5 609
佛祖请我去吃肉
佛祖请我去吃肉 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:38

    It seems JSONObject doesn't support enums. You could alter your Job class to add a getter like this:

    public String getStatus() {
        return status.name();
    }
    

    then, invoking new JSONObject(job).toString() produces:

    {"id":"12345","status":"INPROGRESS"}
    

提交回复
热议问题