Skip to content
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

Ignore unmapped properties in YAML #88

Closed
wants to merge 4 commits into from

Conversation

nickbabcock
Copy link
Contributor

Given a YAML file that contains more information than the object deserializing it, the current implementation will throw an exception because there is not a corresponding object property for all properties in the YAML file. This fixes the issue (or at least starts to address it).

It seems that there would be some interest in this solution.

Let me know what else I need to do to integrate this code.

@aaubry
Copy link
Owner

aaubry commented Feb 21, 2014

Thanks for this contribution. There is definitely interest in supporting this use case.

Regarding your implementation, I don't think that ObjectNodeDeserializer should depend on the naming convention, because the naming convention is already applied in the type descriptor. I think it would be better if the type inspectors stopped throwing exceptions when the property is not found, returning null instead. Then ObjectNodeDeserializer would be responsible of throwing the exception or ignoring the property, depending on the ignoreUnmatched flag.

What do you think?

@RebelusQuo
Copy link
Contributor

Not that I have an alternative to offer, but passing null between objects isn't the best of code designs..

@nickbabcock
Copy link
Contributor Author

@aaubry: I can definitely work on that.

@rogernorling: Sorry I don't understand. Do you mean the resulting deserialized object may have null properties, or that my implementation passes around null objects?

@aaubry
Copy link
Owner

aaubry commented Feb 22, 2014

@rogernorling Yes, I agree with you. That's the first idea that I came up
with, but we could try to come up with a better design. My main concern is
to try to keep responsibilities in the proper place.
On Feb 21, 2014 11:47 PM, "Roger Norling" notifications@github.com wrote:

Not that I have an alternative to offer, but passing null between objects
isn't the best of code designs..

Reply to this email directly or view it on GitHubhttps://github.com//pull/88#issuecomment-35785781
.

@RebelusQuo
Copy link
Contributor

@nickbabcock: I referred to aaubry's idea to pass null to the ObjectNodeDeserializer.

@nickbabcock
Copy link
Contributor Author

Went with a modified solution. Type inspectors return null if the property isn't found and the parameter is set to ignore unmatched.

Some consideration of design: I didn't want to inject it into the constructor because then I felt like this option would have to be propagated to all decorator classes, which I felt would be overkill. I also thought about adding the property IgnoreUnmatched to ITypeInspector, but since it would only affect a single function, better just to add it as a parameter.

@aaubry
Copy link
Owner

aaubry commented Feb 28, 2014

Merged manually in acdde89

@aaubry aaubry closed this Feb 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants