在Java Spring项目中,我有枚举:
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum ResponseStatus {
SUCCESS (0,"OK"),
SYSTEM_UNAVAILABLE (1001, "System Unavailable"),
SYSTEM_INTERNAL_ERROR (1002, "System Internal Error"),
APPLICATION_FUND_LOAN_COMPLETED (4015, "Application Fund Loan Completed");
private int code;
private String message;
private ResponseStatus(int code, String message) {
this.code = code;
this.message = message;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
我不得不把这个Enum移到Pure Java项目中。对于这种情况,是否有类似JsonFormat的解决方案?
答案 0 :(得分:0)
您可以使用自己的类来序列化对象:
@JsonSerialize(using = YourSerializer.class)
public enum ResponseStatus {...
这是详细信息的链接:more info