Skip to content

Regression in deserializing @language inside @context (from #63) #329

@shravan2x

Description

@shravan2x

Describe the bug

In #63, the library added support for deserializing @context objects. But it appears that OP's original example doesn't deserialize any more. I've seen schema.org data in the wild that uses this format.

@RehanSaeed your comment #63 (comment) mentioned the test case below but it wasn't included in the PR so did not trigger any failures. This test case does not pass any longer

private const string JsonWithLanguageInContext =
    "{\r\n" +
        "\"@context\": [ \"http://schema.org\", { \"@language\": \"it\" } ],\r\n" +
        "\"@type\": \"LocalBusiness\",\r\n" +
        "\"@id\": \"https://example.com/mario-rossi-srl\",\r\n" +
        "\"name\": \"Mario Rossi\"\r\n" +
    "}";

[Fact]
public void DeserializeObject_WithLanguageInContext_DeserializesSuccessfully()
{
    var localBusiness = JsonConvert.DeserializeObject<LocalBusiness>(JsonWithLanguageInContext);

    // Asserts....
}

The cause appears to be that this line of code tries to deserialize the array as an object, which fails. It could be fixed by adding a separate else-if for arrays.

Steps to reproduce

  1. Run the test case included above

Expected behaviour

  1. Model deserializes correctly.

Schema objects

No response

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