Skip to content

Exception thrown "The converter 'Schema.NET.ValuesJsonConverter' read too much or not enough." #417

Open
@dermotblairca

Description

@dermotblairca

Describe the bug

When deserializing certain json from websites, SchemaSerializer.DeserializeObject throws the following exception "The converter 'Schema.NET.ValuesJsonConverter' read too much or not enough.".
This is being thrown from System.Text.Json with the following stack trace

at System.Text.Json.ThrowHelper.ThrowJsonException_SerializationConverterRead(JsonConverter converter)
   at System.Text.Json.Serialization.JsonConverter`1.VerifyRead(JsonTokenType tokenType, Int32 depth, Int64 bytesConsumed, Boolean isValueConverter, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
   at Schema.NET.SchemaSerializer.DeserializeObject[T](String value) in C:\Github\Schema.NET\Source\Common\SchemaSerializer.cs:line 52
   at Schema.NET.Test.Examples.ProductTest.Deserializing_ProductJsonLd_HasComment() in C:\Github\Schema.NET\Tests\Schema.NET.Test\Examples\ProductTest.cs:line 91

Steps to reproduce

Run the following unit test:

[Fact]
public void Deserializing_ProductJsonLd_HasComment()
{
    var productJson = "{\"@context\":\"http://schema.org\",\"@type\":\"Product\",\"review\":[[]]}";

    var exceptionMessage = string.Empty;
    try
    {
        var product = SchemaSerializer.DeserializeObject<Product>(productJson);
    }
    catch (System.Text.Json.JsonException ex)
    {
        exceptionMessage = ex.Message;
    }

    Assert.Equal(string.Empty, exceptionMessage);
}

I got the above json from the following webpage: https://www.nahdionline.com/ar/koleston-hair-color-natural-black-developer-302-0
Schema.org validator does not show any issues with it: https://validator.schema.org/#url=https%3A%2F%2Fwww.nahdionline.com%2Far%2Fkoleston-hair-color-natural-black-developer-302-0

Expected behaviour

SchemaSerializer.DeserializeObject returns an object and does not throw an exception.

Schema objects

https://schema.org/Product (but affecting all objects)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues describing a bug or pull requests fixing a bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions