How to make parse object to json using retrofit : <p>with the next problem, when trying to consume a webservice, then message and presentation;</p>

<p>Expected BEGIN_ARRAY but was BEGIN_OBJECT</p>

<p>I'm not sure how to make a scenario, I've already got data from a webservice, but when it's not a simple array.</p>

<p>I have tried many alternatives, but without success.</p>

<p><strong>response api</strong></p>

<pre><code>  {
    "_links": {
        "self": {
            "href": "http://url.com/service?page=1"
        },
        "first": {
            "href": "http://url.com/service"
        },
        "last": {
            "href": "http://url.com/service?page=1"
        }
    },
    "_embedded": {
        "data": [
            {
                "id": 1,
                "nome": "teste",
                "_links": {
                    "self": {
                        "href": "http://url.com/service/1"
                    }
                }
            },
            {
                "id": 2,
                "nome": "teste 2",
                "_links": {
                    "self": {
                        "href": "http://url.com/service/2"
                    }
                }
            }
        ]
    },
    "page_count": 1,
    "page_size": 25,
    "total_items": 2,
    "page": 1
}
</code></pre>

<p><strong>Client</strong></p>

<pre><code>public class ApiClient {

    private static final String BASE_URL = "http://url.com/";


    private static Retrofit getClient() {

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        Gson gson = new GsonBuilder().setLenient().create();

        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();
    }

    /**
     * Get API Service
     *
     * @return API Service
     */
    public static ApiInterface getApiService() {
        return getClient().create(ApiInterface.class);
    }

}
</code></pre>

<p><strong>Interface</strong></p>

<pre><code>/**
 * Class ApiInterface
 */
public interface ApiInterface
{

    @Headers("Accept: application/json")
    @GET("/service")
    Call&lt;ArrayList&lt;ServiceData&gt;&gt; getData();


}
</code></pre>

<p><strong>Service</strong></p>

<pre><code>public class Service{

    @SerializedName("data")
    private ArrayList&lt;ServiceData&gt; service = new ArrayList&lt;&gt;();

}
</code></pre>

<p><strong>Service Data</strong></p>

<pre><code>public class ServiceData {
    @SerializedName("id")
    private int id;


    public ServiceData(int id, String nome) {
        this.id = id;

    }

    public int getId() {
        return id;
    }

}
</code></pre>

<p><strong>Activity</strong></p>

<pre><code> final Call&lt;ArrayList&lt;ServiceData&gt;&gt; service = apiService.getService();
        service.enqueue(new Callback&lt;ArrayList&lt;ServiceData&gt;&gt;() {
            @Override
            public void onResponse(Call&lt;ArrayList&lt;ServiceData&gt;&gt; call, Response&lt;ArrayList&lt;ServiceData&gt;&gt; response) {
                Log.e(TAG, "" + response.body());
            }

            @Override
            public void onFailure(Call&lt;ArrayList&lt;ServiceData&gt;&gt; call, Throwable t) {
                Log.e(TAG, "" + t);

            }
        });
</code></pre>
