ahm*_*och 6 java android json retrofit retrofit2
我使用Microsoft.Net和Breeze for API,我使用Retrofit得到的结果嵌套了重复的相同对象.例如,EmployeeJob具有Customer导航属性,因此API结果如下所示
{
Id:1,
"Customer_Id": 39,
"Customer": {
"$id": "2",
"$type": "Wit.Trade.Entities.Customer, Wit.Trade",
"CourtesyTitle": "Mr",
"FirstName": "Ahmad"
}
}
{
Id:2
"Customer_Id": 39,
"Customer": {
"$ref": "2" //here same customer Ahmad
},
}
Run Code Online (Sandbox Code Playgroud)
现在List我得到的Java EmployeeJobs只有Customer第一个记录而其他人什么都没有.如何$ref:"2"将其映射到其原始值而不是此值$ref.
我不希望我的服务器API出于网络和性能原因发送完整的对象,这就是为什么我想$refs在客户端反序列化这些就像Angularjs $resource service我们一样.
目前我已经手动解决了这样的 $ref 解决方案
//========== $ref manual solution for employee jobs' customers
List<Customer> completedCustomers = new ArrayList<>();
for (EmployeeJob empJob : empJobs) {
if (empJob.Customer != null && empJob.Customer.Id == null && empJob .Customer.$ref != null) {
for (Customer comCus : completedCustomers) {
if (comCus.$id.equalsIgnoreCase(empJob.Customer.$ref))
empJob.Customer = comCus;
}
} else
completedCustomers.add(empJob.Customer);
}
Run Code Online (Sandbox Code Playgroud)
现在empJobs$refs 已替换为其相应的客户。
| 归档时间: |
|
| 查看次数: |
215 次 |
| 最近记录: |