json-iterator / go

A high-performance 100% compatible drop-in replacement of "encoding/json"
http://jsoniter.com/migrate-from-go-std.html
MIT License
13.33k stars 1.02k forks source link

Fix #657 incorrect encoding of embedded-recursive types and overlapping tags #659

Open ngicks opened 1 year ago

ngicks commented 1 year ago

Just to explore how to fix #657 .

A simple fix to recursive embedded types is to add recursion check. This, however, breaks other test cases.

I found that it is hard to fix the problem by changing the current resolveConflictBinding implementation, because it does it without field information, while Go's dominantField does it with field info. Adding the overlapping-field-resolver implementation almost identical to that of the std's encoding/json, of course, fixes the problem.

This PR introduces significant changes to the code base (at least it's not like 50 lines fix). So this might not be suitable for the goal of this library.