1

当我尝试反序列化时:

{
  "tags": {}
}

进入:

public static class Foo
{
    private final Set<URI> tags;

    /**
     * Creates a new Foo entity.
     * <p/>
     * @param tags the room tags
     * @throws NullPointerException if tags is null
     */
    @JsonCreator
    public Foo(@JsonProperty("tags") Set<URI> tags)
    {
        Preconditions.checkNotNull(tags, "tags may not be null");

        this.tags = ImmutableSet.copyOf(tags);
    }

    /**
     * @return the tags
     */
    public Set<URI> getTags()
    {
        return tags;
    }
}

我得到:

org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.HashSet out of START_OBJECT token
 at [line: 1, column: 2]

这不应该开箱即用吗?

4

2 回答 2

4

为此,您需要转换为数组:

{
  "tags": []
}

如果不是,您将如何使用有效的 JSON 表示标签集中的多个元素?

于 2012-06-18T20:23:39.440 回答
0

我的问题是映射有效负载,请确保:

  • 字段相同(有效负载和对象),或者您正确使用 @JsonProperty
  • 您需要在对象上创建设置器以框架填充字段

我希望它有帮助

于 2016-10-26T11:56:00.080 回答