Skip to content

Fully qualified property names not recognized in deserialization #692

@Buthrakaur

Description

@Buthrakaur

Describe the bug

Property names can be fully qualified (prefixed with namespace) in Schema.org JSON the deserialization doesn't seem to work for that. I'm trying to use this library for Schema.org based API integration.

Steps to reproduce

Copy of part of data from the test https://github.com/RehanSaeed/Schema.NET/blob/main/Tests/Schema.NET.Test/Examples/RestaurantTest.cs#L63 with fully qualified property names in a test which fails:

        var json =
        """
        {
            "@context": "https://schema.org",
            "@type": "Restaurant",
            "@id": "https://davessteakhouse.example.com",
            "name": "Dave's Steak House",
            "https://schema.org/address": {
                "@type": "PostalAddress",
                "addressCountry": "US",
                "addressLocality": "New York",
                "addressRegion": "NY",
                "postalCode": "10019",
                "https://schema.org/streetAddress": "148 W 51st St"
            }
        }
        """;
        var restaurant = SchemaSerializer.DeserializeObject<Restaurant>(json)!;

        // following throws as restaurant.Address is not populated
        restaurant.Address.HasValue.ShouldBeTrue();
        restaurant.Address.OfType<PostalAddress>().Single().StreetAddress.Single().ShouldBe("148 W 51st St");

Expected behaviour

Deserialization should populate even properties with fully qualified names - this is valid according to Schema.org definition
image

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