-
Notifications
You must be signed in to change notification settings - Fork 11
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
Reporting missing fields deeper in structure #26
Comments
@marek-kuticka thank you for this. |
thx a lot for the encouragement. I indeed know, where the issue might approx be, but as a Go beginner, I am not sure about possible solution. I might try to do it however. I must admit, that the combination of "known fields" and error handling for unknown ones seems to be quite nice. I will let you know, if I can find some proper solution. If possible, pls look at it too, to confirm, it's a bug. Marek |
@marek-kuticka sorry for the slight delay, hope you haven't started. TL;DR - we want nested objects in the resulting map to be of the same type as in the resulting struct. in your example: we want However, the issue of losing unknown fields in nested objects has already been addressed in issue #15, and the solution is to implement the |
This is briefly mentioned in the API section of the readme, but I would love to get your feedback on how else would you document this to make it clearer. |
here I have attached link to my fork, where I added testcases to confirm the bug I have noticed your coment also before , in the API Section, and I have also read through the mentioned issue, but .. when looking into the code, the culprit imho lies in buildStruct method
as... I HAVE to have this "unknown" field in my class, so that I can assign a handler to it. , there is a method created for this in the playground showcase. in the use-case I am solving right now ( so far no code in GitHub, that would be public ) is, that I have approx 40k JSON files, that COULD be a bit different in deeper levels. that means, although I create Go structures to cover most of the json files, there might be some member, deep in structure, that I omit. I don't even know, I have the field there... and I need to find out. and I'd like exactly this to be caught by the code. What do you think about this? |
Think I know now, what you were meaning after adding
to the test class, I got output about field "unknown", which indeed is the expected behavior, only issue I feel here is, that I had to create this method for the PersonAddress inner struct. if this is created for main struct only, then I will not catch this error. |
@marek-kuticka I would suggest you simply implement |
I agree, that this approach you suggested is working, and I also agree, that it's not so easy to remember, where in the tree we are currently traversing. thx for valuable discussion. closing the issue. |
Having a json:
{"field1": "val", "field2" : {"field3" : "value", "unknown" : { "inner" : "val1", "inner2" : "val2" }}}
and structures:
unmarshall.go does not report the "unknown" key at all.
see comments inside code from unmarshall.go
would there be an option to modify the code?
best would be to have an information, that "field2.unknown" field is not correctly mapped in data.
thank you
Marek
The text was updated successfully, but these errors were encountered: