Currently, if a member is marked with @required trait and you run deserialization on a object without such field, the deserialization fails with software.amazon.smithy.java.core.serde.SerializationException:
Caused by: software.amazon.smithy.java.core.serde.SerializationException: Missing required members: [result]
at software.amazon.smithy.java.core.schema.PresenceTracker.validate(PresenceTracker.java:57)
This creates a couple of issues:
- it feels like this behavior is different from other traits (but I understand that the nature of other traits is different as well) - for them you have either to run a
Validator or validate themselves
- if you want to treat such situation as "validation error", then it is not quite possible because
SerializationException is generic and 1) it doesn't have a list of fields that are missing (the list above is just a string created here), 2) if a field is missing in a sub-object, then it is even harder to distinguish because for instance Caused by: software.amazon.smithy.java.core.serde.SerializationException: Missing required members: [id] doesn't tell where exactly id is missing
- there is a
errorCorrection method on builder that in theory can be useful, but it feels like its purpose is completely different
I understand that I guess it is rather a philosophical question whether to treat the result of @required as "malformed input" (e.g. similar to when an input is not valid json) or "validation error" (when the structure and types are valid, but values aren't aligned to validation) so seeking for your thoughts on this.
Essentially:
- if you think that
@required is an indicator of "malformed input", then can we at least change the exception being thrown to 1) be specific rather a generic 2) contain a list of all field paths which are missing, instead of just one field somewhere
- if you think that it can be/is "validation error" then have an option to
@required tracking while deserializing an object and add its validation to the validator
Thanks!
Currently, if a member is marked with
@requiredtrait and you run deserialization on a object without such field, the deserialization fails withsoftware.amazon.smithy.java.core.serde.SerializationException:This creates a couple of issues:
Validatoror validate themselvesSerializationExceptionis generic and 1) it doesn't have a list of fields that are missing (the list above is just a string created here), 2) if a field is missing in a sub-object, then it is even harder to distinguish because for instanceCaused by: software.amazon.smithy.java.core.serde.SerializationException: Missing required members: [id]doesn't tell where exactlyidis missingerrorCorrectionmethod on builder that in theory can be useful, but it feels like its purpose is completely differentI understand that I guess it is rather a philosophical question whether to treat the result of
@requiredas "malformed input" (e.g. similar to when an input is not valid json) or "validation error" (when the structure and types are valid, but values aren't aligned to validation) so seeking for your thoughts on this.Essentially:
@requiredis an indicator of "malformed input", then can we at least change the exception being thrown to 1) be specific rather a generic 2) contain a list of all field paths which are missing, instead of just one field somewhere@requiredtracking while deserializing an object and add its validation to the validatorThanks!