androidrealmlogan-square

Not getting data for anonymous array list


I am using Realm as mobile database and LoganSquare to parse the json data.

i want to parse below mentioned json block return from third party service.

{
    "code": 406,
    "message": "Not Acceptable",
    "errors": [
        "Invalid date range: End date is before start date."
    ]
}

but not sure how would i parse array of error and design error model that has no property name.


Solution

  • Based on at least one example, I am pretty convinced that you could create some class like

    @JsonObject
    public class MyError {
      @JsonField
      public int code;
    
      @JsonField
      public String message;
    
      @JsonField
      public List<String> error;
    }
    

    and use it as MyError error = LoganSquare.parse(jsonString, MyError.class); (inspiration from Parsing JSON)