Java : Convert Object consisting enum to Json Object
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using org.json library to convert Object to Json format. Kindly check the below code snippet. public enum JobStatus implements Serializable{ INCOMPLETE, INPROGRESS, ABORTED, COMPLETED } public class Job implements Serializable { private string id; private JobStatus status; ... } ... // Create Job Object Job job = new Job("12345", JobStatus.INPROGRESS); // Convert and print in JSON format System.out.println(new JSONObject(job).toString()); It shows the output like this : {"id":"12345", "status" : {}} It shows blank and adds Curly bases.