Here I have a Rest Controller
@RequestMapping(value = "/mobileNumber", method = RequestMethod.POST, produces = {
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<ResponseBack> sentResponse() {
return new ResponseEntity<ResponseBack>(ResponseBack.LOGIN_SUCCESS, HttpStatus.ACCEPTED);
}
My Enum
Class
public enum ResponseBack {
LOGIN_SUCCESS(0, " success"), LOGIN_FAILURE(1, " failure");
private long id;
private final String message;
// Enum constructor
ResponseBack(long id, String message) {
this.id = id;
this.message = message;
}
public long getId() {
return id;
}
public String getMessage() {
return message;
}
}
When I get the response back from the controller I am getting it as
"LOGIN_SUCCESS"
What I require is
{
"id": "0",
"message": "success"
}
How can I deserialize it to Json and send response, is there any annotation for it.
Please help, thanks.
question from:
https://stackoverflow.com/questions/65859893/convert-enum-multiple-values-to-json-in-java-springboot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…