对象转json的时候对象中的枚举类型只会转化枚举的name其它的属性不会带
16 回复
public enum LoanPushStatus {
STAY_PUSH("1600","待推单"),
PART_PUSHED("1601","部分推单"),
PUSHED("1602","推单完成");
private String code;
private String description;
}
String json = Json.toJson(LoanPushStatus.PART_PUSHED);
这里json的值是“PART_PUSHED”
想起来了, 有这个
package org.nutz.json.meta;
import org.nutz.json.JsonShape;
import org.nutz.json.JsonShape.Type;
@JsonShape(Type.OBJECT)
public enum EnumWithFields {
STAY_PUSH("1600","待推单"),
PART_PUSHED("1601","部分推单"),
PUSHED("1602","推单完成");
private String code;
private String description;
EnumWithFields(String code, String description) {
this.code = code;
this.description = description;
}
}
加上注解就正常了
@JsonShape(Type.OBJECT)
public enum TestEnum {
Test("name", "value");
public final String name;
public final String value;
TestEnum(String name, String value) {
this.name = name;
this.value = value;
}
还是final字段的问题, 之前在git讨论过.
@wendal 我用的是最新的nutzboot, 貌似没有修复这个问题
添加回复
请先登陆