سؤال

Assuming the following JSON structure:

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

Instead of creating two autobean interfaces (one for the whole structure and one for the subtype), I would like to have one which contains all the properties.

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

    String getName();

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

So, the getTotal() method is expected to contain the total property of the nested subtype in the JSON structure. I can't find any documentation in the source code or online which states whether or not this is possible.

Thanks in advance!

هل كانت مفيدة؟

المحلول

Nope: AutoBeans are designed to be a mapping from the JSON structure to Java interfaces, plus or minus collections like List, Set, and Map and String encodings of a long or a Date. Additionally, it is legal to have json like the following:

{
    "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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top