Skip to content

Relative paths are removed from Product #391

@dermotblairca

Description

@dermotblairca

Describe the bug

When a Product has a relative path, for example as the "image" field, this is not returned in the Product object from SchemaSerializer.DeserializeObject.
Maybe this was intentional but it does seem to validate ok in the Schema.org validator. For example: https://validator.schema.org/#url=https%3A%2F%2Fwww.thedandys.ie%2Fproduct%2Fsodium-hypochlorite-25ltrs%3Fgclid%3DCj0KCQiAu62QBhC7ARIsALXijXTUddi2aWyH-XjZKJHIuzUSLbH6HiVW883I7sSdYEtORXVeeALdfwkaAnALEALw_wcB
And the schema.org documentation shows relative paths in the examples too (see the example in the JSON-LD tab): https://schema.org/image

Steps to reproduce

Run the following unit test in the ProductTest.cs file:

namespace Schema.NET.Test.Examples;

using System;
using Xunit;

// https://developers.google.com/search/docs/data-types/products
public class ProductTest
{
    [Fact]
    public void Deserializing_ProductJsonLd_ReturnsProduct2()
    {
        var productJson = "{\"@context\":\"http://www.schema.org\",\"@type\":\"product\",\"name\":\"SodiumHypochlorite/RedLabel25Ltrs\",\"image\":\"/site/uploads/sys_products/red-label-hypo.jpg\",\"offers\":{\"@type\":\"Offer\",\"price\":\"22.00\",\"availability\":\"http://schema.org/InStock\",\"priceCurrency\":\"EUR\"}}";
        var productObject = SchemaSerializer.DeserializeObject<Product>(productJson);
        var productBackToString = productObject?.ToString();
        var hasImagePath = productBackToString?.IndexOf("/site/uploads/sys_products/red-label-hypo.jpg", StringComparison.OrdinalIgnoreCase) > 0;
        Assert.True(hasImagePath);
    }
}

Expected behaviour

The image should be included in the Product object.

Schema objects

https://schema.org/Product (but I think this would affect any class derived from Thing)

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