0

Using the System.Text.Json deserializer doesn't produce the expected results. There are no errors thrown, just a list without values....all object properties are null.

Here is a working example: https://dotnetfiddle.net/QYrvy5

Here is the code in question. "data" is just a json string (see dotnet fiddle):

  products = JsonSerializer.Deserialize<List<ProductCatalogProduct>>(data);
dbc
  • 104,963
  • 20
  • 228
  • 340
Will Lopez
  • 2,089
  • 3
  • 40
  • 64
  • Have you tried to debug your code and check a property names in json and c# classes? – Pavel Anikhouski Apr 05 '20 at 13:44
  • 2
    got it to work, 2 things: 1) POCO need parameterless constructors and 2.) added options to deserialer call (var options = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true };) – Will Lopez Apr 05 '20 at 13:48
  • 1
    You can also solve it by adding `PropertyNamingPolicy = JsonNamingPolicy.CamelCase` to `JsonSerializerOptions` – Pavel Anikhouski Apr 05 '20 at 13:50

0 Answers0