-
Notifications
You must be signed in to change notification settings - Fork 215
Embedded structs v3 #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Embedded structs v3 #100
Conversation
…top-level to embedded
…aler/Unmarshaler" This reverts commit deeffb7.
}) | ||
} | ||
for _, scenario := range scenarios { | ||
t.Logf("running scenario: %s\n", scenario.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skimata please submit pr to use t.Run
* working version * fix text * combine test files * move private funcs to bottom * ErrInvalidType should ignore interfaces * replace MarshalOnePayload w/ MarshalPayload; fix bug w/ node merge() * minor tweaks; address a couple comments * decompose unmarshalNode() to smaller funcs; unmarshal should go from top-level to embedded * deep copy the node when passing relation/sideloaded notes to unmarshal() * add some comments and do some additional cleanup * add test uses annotationIgnore * implement support for struct fields that implement json.Marshaler/Unmarshaler * add additional test that compares marshal/unmarshal behavior w/ standard json library * add support for pointer embedded structs * Revert "implement support for struct fields that implement json.Marshaler/Unmarshaler" This reverts commit deeffb7.
Is there a reason, that this MR got merged into |
it looks like this will never be supported huh ? |
this is an update to #78. I found it cleaner and more convenient to just cherry-pick my changes in the latest google/jsonapi.
All comments made to the last PR should be addressed here. Addressing the last comment in that PR required some refactor/enhancements, hence took some time.
I added these additional examples:
The expected behavior is that it will behave in the "expected" composition behavior; it will handle the top-level struct fields first, then handle any embedded structs after that. So in the scenario where there is a top-level struct that has a primary annotation, that embeds another struct also containing a primary annotation, the top-level attribute wins. (In the below example, the expected jsonapi payload should have a data/resource type of "posts")
Lastly, I felt it was getting complex and a bit messy, so I started splitting out
unmarshalNode()
into smaller functions for better readability.Happy to add something to the readme.md if you think that would be useful