I have the usual json server response. Example: {"id": 58339}
But when you start the application, an error occurs that the expected array, but in the response object. As far as I understand, the application needs an array of objects (example: [{"id": 58339}] ) How can I work with the usual json ( {"id": 58339} )? Example code: @GET("/api/catalog/get-product") Call<List<ProductModel>> getProduct(@Query("id") String id);
private List<ProductModel> product; public String productId; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_product); Intent intent = getIntent(); this.productId = intent.getStringExtra(CatalogAdapter.PRODUCT_ID); App.getApi().getProduct(this.productId).enqueue(new Callback<ProductModel>() { @Override public void onResponse(Call<List<ProductModel>> call, Response<List<ProductModel>> response) { if (response.body() !=null) { product.addAll(response.body()); } } @Override public void onFailure(Call<List<ProductModel>>call, Throwable t) { Toast.makeText(ProductActivity.this, "Нет соединения с интернетом", Toast.LENGTH_SHORT).show(); } }); }
And the model itself
import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import java.util.List; public class ProductModel { @SerializedName("id") @Expose private int id; public int getId() { return id; } }