[英]Retrofit JSON deserializing object's $ref reference to its original copy
I am using Microsoft.Net with Breeze for APIs and the results I get using Retrofit have nested repeated same objects. 我使用Microsoft.Net和Breeze for API,我使用Retrofit得到的结果嵌套了重复的相同对象。 For example EmployeeJob has Customer navigation property so the APIs result looks like this
例如,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
},
}
Now the Java List
I get of these EmployeeJobs
has only Customer
in the first record and others have nothing. 现在我得到的这些
EmployeeJobs
的Java List
在第一条记录中只有Customer
,而其他的则没有。 How can I map the $ref:"2"
to its original value instead of this $ref
. 如何将
$ref:"2"
映射到其原始值而不是$ref
。
I don't want my server APIs to send the complete objects for network and performance reasons, that's why I want to deserialize these $refs
on client side just like Angularjs $resource service
does for us. 我不希望我的服务器API出于网络和性能原因发送完整的对象,这就是为什么我想在客户端反序列化这些
$refs
,就像Angularjs $resource service
为我们做的那样。
Currently I have worked arround manually for the $ref solution like this 目前我已经手动为这个$ ref解决方案工作了arround
//========== $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);
}
Now empJobs
has the $refs replaced with their corresponding Customers. 现在
empJobs
已将$ refs替换为相应的客户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.