【问题标题】:jsonencoderdecoder without getter/setter method没有getter/setter方法的jsonencoderdecoder
【发布时间】:2013-05-30 21:38:17
【问题描述】:

我使用了 RestyGWT 的 JsonEncoderDecoder 接口来编码/解码一些对象。其中有一些类的实例具有未使用 getter/setter 方法公开的属性。我尝试用org.codehaus.jackson.annotate.JsonProperty 注释相应的属性。但它不起作用,导致错误

[错误] [jsonsample] - 字段不能是私有的:com.mycompany.jsonsample.ItemList.items

com.mycompany.jsonsample.ItemList 是具有属性items 的类,它没有getter/setter 并如上所述进行注释。

还有可能告诉编码器/解码器跳过一些属性吗?

【问题讨论】:

  • 你能给出你想用resty反序列化的json和所涉及的类吗?

标签: json gwt resty-gwt


【解决方案1】:

带有私有字段和带注释的构造函数的示例,您应该提供有关您的问题的更多信息。

public abstract class Parent
{    
    @JsonCreator
    public Parent(@JsonProperty("name") String name)
    {
        this.name = name;
    }

    @Override
    public String getName()
    {
        return name;
    }

    private String name;
}

【讨论】:

    猜你喜欢
    • 2011-04-14
    • 2017-09-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 1970-01-01
    相关资源
    最近更新 更多