alibaba / fastjson

FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
https://github.com/alibaba/fastjson2/wiki/fastjson_1_upgrade_cn
Apache License 2.0
25.74k stars 6.5k forks source link

@JSONField 在enum field上没有作用 #1932

Open Zane-XY opened 6 years ago

Zane-XY commented 6 years ago

在enum上的 @JSONField 在parse的时候起到了作用,但是在toString的时候,并没有使用name中指定的key, 仍然打印出 "type":"enumeration", 期望的是 "type":"enum"。

public class AttributeTypeDesc {
    private AttributeType type;
   /* setter getter */
}

enum AttributeType {
    number,
    string,
    @JSONField(name = "enum")
    enumeration;
}

AttributeTypeDesc typeEnum = JSON.parseObject("{\"type\":\"enum\"}", AttributeTypeDesc .class);

JSON.toJSONString(typeEnum)      
wenshao commented 6 years ago

这个不支持哦

kelunik commented 6 years ago

This feature would be really nice to have.

kelunik commented 6 years ago

Actually, this feature seems to be supported in recent versions. :tada: