2

I am using LoganSquare with Retrofit to consume data from a web service.

For one particular API, the web service returns a relatively complex JSON response, and the only piece of information I am interested in is nested a couple of layers deep. e.g.,

{"outer": { "middle": { "inner": ... }}}

Since I'm only interested in the inner value, I created a data object like:

@JsonObject
class MyData implements Serializable {
    @JsonField(name = "outer.middle.inner")
    public String inner;
}

And I've mapped the return value of the web service to this data type.

However, it appears it was just wishful thinking that this dot syntax (outer.middle.inner) would do what I had hoped, as the field is not mapped upon successful invocation of the method.

Is there any way to map a field in a LoganSquare JSON object to a nested value?

Myk Willis
  • 12,306
  • 4
  • 45
  • 62

1 Answers1

0

I think you have to declare each JsonObject as an inner class so:

@JsonObject
public class MyData implements Serializable {
    @JsonObject
    public static class Outer {
        @JsonObject
        public static class Middle {
            @JsonField
            public String inner;
        }
    }
}     
jt-gilkeson
  • 2,661
  • 1
  • 30
  • 40