在我的Android应用程序中,我使用Retrofit来描述内部API:
@Provides
@Singleton
ProductsService provideProductsService() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setPropertyNamingStrategy(
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
RestAdapter.Builder restAdapterBuilder = new RestAdapter.Builder()
.setConverter(new JacksonConverter(objectMapper));
return restAdapterBuilder
.setEndpoint(Endpoints.newFixedEndpoint("http://192.168.1.1"))
.build()
.create(ProductsService.class);
为了阅读 ProductLevels ,我创建了以下界面:
public interface ProductsService {
@GET("/api/products/{productId}/levels/")
public Observable<List<ReadProductLevelsResponse>> readProductLevels(
@Path("productId") int productId
);
}
以下是后端提供的JSON字符串:
[
[
1427378400000,
553
],
[
1427382000000,
553
]
]
当我尝试读取空 ReadProductLevelsResponse 类中的JSON数据时,会发生以下错误:
com.fasterxml.jackson.databind.JsonMappingException:无法在[Source:retrofit.ExceptionCatchingTypedInput $ ExceptionCatchingInputStream@11ae0f16;来源:START_ARRAY标记中反序列化ReadProductLevelsResponse的实例。 line:1,column:2](通过引用链:java.util.ArrayList [0])
如何将JSON数据读入 ReadProductLevelsResponse 类?