gpt4 book ai didi

java - FlexJson 和 @JSON 注释 - @JSON(name = "") 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:00 25 4
gpt4 key购买 nike

我刚切换到 FlexJson,但我已经遇到了问题。

文档位于 http://flexjson.sourceforge.net/ , Controlling JSON naming with @JSON 一章指出:

When an object is serialized the names of the properties on JSON objects are determined from the name of the Java property. This means the names of the getter methods or the field names are used. However, sometimes the JSON output doesn't match the names used by the Java object. You can control this using the @JSON annotation. For example:

    public class Species {
@JSON(jsonName = "genus")
private String type;

private String name;

@JSON(jsonName="species")
public String getName() {
return name;
}
}

除非它不起作用。然后他们说:

Defining a @JSON.jsonName is used in both serialization and deserialization.

现在,当我在 http://flexjson.sourceforge.net/javadoc/index.html 查看 javadoc 时,我可以看到有 4 个可选元素属于 @JSON 注释,它们是

include name objectFactory transformer

都不是 jsonName,就像示例中那样。

那么如何让这个注解起作用,这样我就可以有不同的 java 和 json 名称呢?如何定义此注释元素或使用预定义的 name

澄清一下,我可以注释@JSON并且自动完成推荐@JSON(include),但是include无法解析...

我使用的是 FlexJson 2.1,我导入了 flexjson.JSON;

顺便说一句,我知道这个答案 https://stackoverflow.com/a/8879616/2001247 ,但这不是我想要的。我想使用注释。

最佳答案

您需要使用FlexJson 3.2

问题是,可通过开发者网站访问的最新 jar 版本号为 2.1。但是java doc对应的是3.2版本。
您可以在 Maven 存储库中找到 FlexJson 3.2 jar。

关于java - FlexJson 和 @JSON 注释 - @JSON(name = "") 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23496359/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com