1

假设以下 JSON 结构:

{
    \"is_something\": false,
    \"name\": \"Some Name\",
    \"subtype\": {
        \"total\": 0.0
    }
}

我不想创建两个 autobean 接口(一个用于整个结构,一个用于子类型),我想要一个包含所有属性的接口。

public interface ExampleAutoBean {
    @PropertyName("is_something")
    boolean isSomething();

    String getName();

    @PropertyName("subtype.total")
    double getTotal();
}

因此,该getTotal()方法有望total在 JSON 结构中包含嵌套子类型的属性。我在源代码或网上找不到任何说明这是否可行的文档。

提前致谢!

4

1 回答 1

4

不:AutoBeans 被设计为从 JSON 结构到 Java 接口的映射,加上或减去集合,如ListSet和a或 a 的Map字符串编码。此外,拥有如下 json 是合法的:longDate

{
    "some.property.with.dots" : "abcd",
    "name" : "wxyz"
}

If the . character could only be used for traversing into sub-objects, there would be no way to have a getter for the first property.

于 2012-09-14T03:13:06.057 回答