想把pojo中枚举字段在server @Ok返回json时直接以枚举里面的descrp字段输出字符串,
用了forceString=true和@ToJson, 但是未能如愿,应该怎么用?
@ToJson
public enum PatrolDirection {
EAST(1, "东"),
SOUTH(2, "南"),
WEST(3, "西"),
NORTH(4, "北"),
EAST_SOUTH(12, "东南"),
SOUTH_WEST(23, "西南"),
WEST_NORTH(34, "西北"),
NORTH_EAST(41, "东北");
public final int patrol_direction;
public final String descrp;
PatrolDirection(int patrol_direction, String descrp) {
this.patrol_direction = patrol_direction;
this.descrp = descrp;
}
public String toJson() {
log.info("toJson() called !!!!!!!!!!!!!!");
return getDescrp();
}
public String toJson(JsonFormat jf) {
log.info("toJson() called !!!!!!!!jf!!!!!!");
return getDescrp();
}
public static PatrolDirection getFromInt(Integer v) {
if(v==null){
return PatrolDirection.EAST;
}
for(PatrolDirection pt : values()){
if(pt.patrol_direction==v){
return pt;
}
}
return PatrolDirection.EAST;
}
public int getValue() {
return patrol_direction;
}
public String getDescrp(){
return descrp;
}
public static PatrolDirection getFromText(String text){
if(text==null){
return null;
}
for(PatrolDirection pt : values()){
if(pt.descrp.equals(text)){
return pt;
}
}
return null;
}
@JsonField(forceString=true)
@Column
@ColDefine(type=ColType.INT, adaptor=PatrolDirectionAdaptor.class)
public PatrolDirection patrol_direction; //巡检方向