-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use serializer when deserializing LazyDocument to T #2791
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
Conversation
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.
LgTM with one q? Maybe add a comment there explaining why we need to write null?
@@ -10,19 +10,24 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s | |||
{ | |||
var d = value as LazyDocument; | |||
if (d?._Value == null) | |||
{ | |||
writer.WriteNull(); |
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.
Why was this change needed?
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.
I think this is an oversight in the implementation; if d
is null
or d.Value
is null
and a value is not written to the writer for it, invalid json can be emitted e.g. if LazyDocument
is assigned to the property of an object and that object serialized, the property name could be written to the writer (depending on serialization settings) so a value must also be written in this case
Can we also add an ovlerload to fix #2408 as part of this PR. Two for one :) |
Also a |
Gotcha |
When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers. Fixes #2788
* Use serializer when deserializing LazyDocument to T When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers. Fixes elastic#2788 * Direct cast * Add non-generic overload for As() Relates elastic#2408 (cherry picked from commit 109bcb0)
When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.
Fixes #2788