Open pkese opened 5 years ago
Did you try to parse Schema option
type? An empty document suggests that the whole thing is optional.
Yeah, yeah, except it is not just the top level...
It's turtles all the way down. :)
I'll just close this - it's probably too much effort for a somewhat obscure use-case.
I'm reopening this one. Because of all the other stuff going on, I've had not taken the time to read your question well enough and to understand it. But I wanted to return to this one when I had some more time.
In
MapYaml.AndRequireFullProjection
with Schema:and an empty document:
There is an expected deserialization error due to full projection not being satisfied. They way to remedy that is to redefine the schema as:
The question here is:
It is unambiguous that a missing
int
should always be reported. Yet for dictionaries, lists and arrays, there is an interpretation, that a missing item might mean an empty dictionary, list or array (maybe someone had their yaml serializer configured to omit serialization of empty dictionaries to save some space).My issue is that the only way to parse such document is to define lists and dictionaries as in
Schema2
. But then each time I'm accessing items in such a dictionary, I have to go through anoption
first and there is a lot of unnecessary and hard to read code.Maybe there could be an option to have another less strict version of
AndRequireFullProjection
that would allow to instantiate empty complex structures that have default initializers (lists, dictionaries, arrays, but not strings or typed structures).As a user, if I'd be interested whether the array was there or not, I could still define my schema as this and still get full control over deserialization results:
This was intended for discussion. I can live with what we have right now, but it gets a bit annoying and verbose.