1

The problem is that I can't parse a simple json array

The structure of jsonarray is:

   [{
    "id": 1,
    "name": "name_1"
   }, {
    "id": 2,
    "name": "name_2"
   }]

I've tried with following code:

@JsonIgnoreProperties(ignoreUnknown = true)
public class MyObject 
{
    public String id;
    public String name;
}

public class RouteServerResponse extends ArrayList<MyObject>
{
    public RouteServerResponse()
    {

    }
}

Method which requests data is:

final JacksonRequest<RouteServerResponse> request = new JacksonRequest<RouteServerResponse>(Request.Method.GET, url, params,
      new JacksonRequestListener<RouteServerResponse>()
                {
                    @Override
                    public void onResponse(RouteServerResponse r, int statusCode, VolleyError error)
                    {
                        if (c != null)
                            c.onResponse(r, statusCode, error);
                    }

                    @Override
                    public JavaType getReturnType()
                    {
                        return SimpleType.construct(RouteServerResponse.class);
                    }
                });

I'm getting this error in logcat

11-14 19:06:08.708  27593-28098/ru.youroute E/Volley﹕ [3991] NetworkDispatcher.run: Unhandled exception java.lang.IllegalArgumentException: Can not construct SimpleType for a Collection (class: ru.youroute.model.serverresponse.impl.RouteServerResponse)
    java.lang.IllegalArgumentException: Can not construct SimpleType for a Collection (class: ru.youroute.model.serverresponse.impl.RouteServerResponse)

1 Answer 1

2

Per Jackson's documentation:

Simple types are defined as anything other than one of recognized container types (arrays, Collections, Maps)

It sounds like you want a CollectionType.

Sign up to request clarification or add additional context in comments.

1 Comment

@bakriOnFire I used something like this: CollectionType.construct(ArrayList.class, SimpleType.construct(Committee.class));

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.