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

JSON Deserialization (using System.Text.Json) in Nested Class Fails #35957

Closed
tlbaxter opened this issue May 7, 2020 · 6 comments
Closed

JSON Deserialization (using System.Text.Json) in Nested Class Fails #35957

tlbaxter opened this issue May 7, 2020 · 6 comments

Comments

@tlbaxter
Copy link

tlbaxter commented May 7, 2020

I'm new here so forgive me if I am not doing something right.

We're using Core v3.1 and trying to deserialize a small bit of JSON. I have this simple class structure, where we are trying to deserialize into A.B.

public class A {
   public class B {
      // some public properties
   }
}

When I try to deserialize into A.B I get an empty object with only default values. Neither of these work:

A.B ab_1 = JsonSerializer.Deserialize(someJson, typeof(A.B));
A.B ab_2 = JsonSerializer.Deserialize<A.B>(someJson);

If I remove the B class from its nesting and make it "stand-alone" I can deserialize into it just fine. Should I not be able to deserialize into A.B?

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels May 7, 2020
@ghost
Copy link

ghost commented May 7, 2020

Tagging subscribers to this area: @jozkee
Notify danmosemsft if you want to be subscribed.

@Symbai
Copy link

Symbai commented May 7, 2020

#30083

@tlbaxter
Copy link
Author

tlbaxter commented May 7, 2020

@jozkee : PLEASE CLOSE THIS ISSUE. MY MISTAKE.

@layomia
Copy link
Contributor

layomia commented May 7, 2020

I couldn't repro this: https://dotnetfiddle.net/49ylUD. @tlbaxter is this why you want the issue closed?

@layomia layomia removed the untriaged New issue has not been triaged by the area owner label May 7, 2020
@layomia layomia added this to the 5.0 milestone May 7, 2020
@tlbaxter
Copy link
Author

tlbaxter commented May 7, 2020

@layomia -- Yes, I made a mistake. So sorry to have wasted your time.

@layomia
Copy link
Contributor

layomia commented May 7, 2020

@tlbaxter, no worries.

@layomia layomia closed this as completed May 7, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants