bluelinelabs / LoganSquare

Screaming fast JSON parsing and serialization library for Android.
Apache License 2.0
3.21k stars 306 forks source link

Parse nested attributes without nested objects #190

Open mdelgado opened 7 years ago

mdelgado commented 7 years ago

Hi, I've run into this situation in various projects and I was wondering if there's a way to retrieve nested properties without using nested objects.

The problem starts when I'm provided with a web api which gives a non-optimal response structure and neither is there a possibility to optimize it, for example something like the following JSON:

{
    result: {
        errors: [
            {
                message: "Some error"
            }
        ]
    }
}

Yeah, as awful and ilogical as it seems, I've had to deal with those kind of responses which make me create unnecesary nested objects just to extract that message.

What I'd like to be able to do is something like this:

@JsonObject
public class Result {
    @JsonField(name = "result/errors[0]/message")
    protected String error;
}

Please consider adding this feature, it'd be awesome to be able to write clean code like that.

Thanks!