Skip to content

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

Merged
merged 3 commits into from
Jun 29, 2017
Merged

Use serializer when deserializing LazyDocument to T #2791

merged 3 commits into from
Jun 29, 2017

Conversation

russcam
Copy link
Contributor

@russcam russcam commented Jun 27, 2017

When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.

Fixes #2788

Copy link
Member

@Mpdreamz Mpdreamz left a 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();
Copy link
Member

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?

Copy link
Contributor Author

@russcam russcam Jun 27, 2017

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

@Mpdreamz
Copy link
Member

Can we also add an ovlerload to fix #2408 as part of this PR.

Two for one :)

@russcam
Copy link
Contributor Author

russcam commented Jun 28, 2017

What overload were you thinking of for #2408, @Mpdreamz?

@Mpdreamz
Copy link
Member

@russcam
Copy link
Contributor Author

russcam commented Jun 28, 2017

Gotcha

russcam and others added 3 commits June 29, 2017 13:08
When converting a LazyDocument to type T, use the JsonNetSerializer configured, along with all registered contract resolvers.

Fixes #2788
@russcam russcam merged commit 109bcb0 into 5.x Jun 29, 2017
russcam added a commit that referenced this pull request Jun 29, 2017
* 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 #2788

* Direct cast

* Add non-generic overload for As()

Relates #2408

(cherry picked from commit 109bcb0)
russcam added a commit that referenced this pull request Jun 29, 2017
* 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 #2788

* Direct cast

* Add non-generic overload for As()

Relates #2408

(cherry picked from commit 109bcb0)
@russcam
Copy link
Contributor Author

russcam commented Jun 29, 2017

ported to 2.x in c77ee31
ported to master in bd71ff8

@russcam russcam deleted the fix/2788 branch June 29, 2017 03:14
awelburn pushed a commit to Artesian/elasticsearch-net that referenced this pull request Nov 6, 2017
* 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)
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.

2 participants