I'm currently dealing with 2 systems that expose interop via their own RESTful JSON APIs. One is in C# with JSON.NET and one is Java Spring Boot Starter (Jackson JSON). I have full control over both systems.
Both systems need to transfer JSON data with reference handling. Whilst both JSON serialization frameworks support it, C# JSON.NET uses "$id" and "$ref" syntax to signify references whilst Java's Jackson uses something plainer with only "id".
I am much less familiar with Java than I am C# so I would more readily accept and understand any solution on getting JSON ref handling working both ways on the C# side. How can I get these two systems to interop with JSON refs?
C# JSON.NET reference handling documentation.
Example JSON coming from Java Jackson
Note that it is possible to mark up what class property Jackson uses as the reference. In this case I am using the Id variable as it will always locally unique to the type.
{
"Resources": [
{
"Id": 0,
"Name": "Resource 0"
},
{
"Id": 1,
"Name": "Resource 1"
}
],
"Tasks": [
{
"Id": 0,
"Name": "Task 0",
"Resource": 0
},
{
"Id": 1,
"Name": "Task 1",
"Resource": 1
},
{
"Id": 2,
"Name": "Task 2",
"Resource": 0
},
{
"Id": 3,
"Name": "Task 3",
"Resource": 1
},
{
"Id": 4,
"Name": "Task 4",
"Resource": 0
}
]
}