Say your calling a REST service from your javascript code in the browser. Your REST service returns a complex object hierarchy in JSON representation. If you want a concrete example say a claim in the insurance industry. Any best practices for dealing with this situation? I only can imagine it would get very messy especially when trying to create or update existing objects through a PUT/POST (create an claim or update a claim). If your not careful i imagine you could end up with a very tightly coupled mess. I guess the same could also be said if your client isn’t web/javascript too.
Share
So, I believe you’re talking about the depth at which a resource should be represented when returning, creating, or editing.
That can indeed be tricky, and there’s no hard and fast rule. One thing you definitely want to do is flatten a graph, so you don’t have circular references to be serialized.
Imagine you have
If you serialize the Claim graph verbatim, you’ll have a circular reference when it attempts to serialize the Owner property, because it will serialize Claims, which will serialize Owners, etc.
Outside of that, what you should include in the serialized graph should be limited to what you deem is essential to servicing client requests.