I have got a scenario to return list of status as json which are available in Status Enum, My Enum Looks below
Example:-
public enum Status {
CREATED("100", "CREATED"), UPDATED("200", "UPDATED"), DELETED("300", "DELETED");
private final String id;
private final String name;
private Status(String id, String name) {
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
public List<Map<String, String>> lookup() {
List<Map<String, String>> list = new ArrayList<>();
for (Status s : values()) {
Map<String, String> map = new HashMap<>();
map.put("ID", s.getId());
map.put("name", s.getName());
list.add(map);
}
return list;
}
}
need the output like this:
[{id:"100",name:"CREATED"},{id:"200", name:"UPDATED"}...] I have written lookup method with List Of maps to build the response, Is there any better way or utility to convert the Enum to Object with all the properties available in Enum.
Is there any better way to do this?