fastjson 1.2.20版本WriteEnumUsingToString无效

mec1mxoz  于 2021-11-27  发布在  Java
关注(0)|答案(0)|浏览(218)
public enum EnumType {
    A, B;
    @Override
    public String toString() {
        return name().toLowerCase();
    }
}

public class Mock {

    @JSONField(serialzeFeatures = {SerializerFeature.WriteEnumUsingToString})
    private EnumType type;

    public EnumType getType() {
        return type;
    }

    public void setType(EnumType type) {
        this.type = type;
    }
}

public class Test {

    @Test
    public void test() {
        Mock mock = new Mock();
        mock.setType(EnumType.A);
        Assert.assertEquals("{\"type\":\"a\"}", JSON.toJSONString(mock));
    }

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题