Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a json property starts with a capital letter, it is not included in the deserialized object #546

Open
dermotblairca opened this issue Dec 21, 2022 · 2 comments
Labels
bug Issues describing a bug or pull requests fixing a bug.

Comments

@dermotblairca
Copy link
Contributor

dermotblairca commented Dec 21, 2022

Describe the bug

For example, if the price on the offer is "Price", it will not be picked up.

Steps to reproduce

This unit test reproduces the issue:

[Test]
public void GetSchemaOrgOffers_GetOfferInProduct_GetPrice()
{
    // Arrange
    var pageContent = File.ReadAllText("C:/SchemaOrgTestPages/SchemaNetProductExample.json");

    // Act
    var product = SchemaSerializer.DeserializeObject<Product>(pageContent);

    // Assert
    Assert.IsTrue(product.Offers.Value2.Any(o => o.Price.HasValue1 || o.Price.HasValue2));
}

The contents of the SchemaNetProductExample file is:

{
	"@context": "http://schema.org/",
	"@type": "Product",
	"name": "Cucumber Mint Lip Balm",
	"title": "Cucumber Mint Lip Balm",
	"image": "https://www.burtsbees.com/dw/image/v2/AAPA_PRD/on/demandware.static/-/Sites-burtsbees-master-catalog/default/dw19603097/images/large/NI-44070_BBd_LIP_CB_4Pk_CucumberMint_Frnt_13-07-18-1300.jpg?sw=380&sh=380&sm=fit",
	"description": "",
	"brand": "Burt's Bees",
	"sku": "792850905337",
	"gtin": "792850900936",
	"size": "4 Pack",
	"color": "",
	"offers": {
		"@type": "Offer",
		"url": "https://www.burtsbees.com/product/cucumber-mint-lip-balm/VM-792850900936.html",
		"priceCurrency": "USD",
		"Price": "11.99",
		"availability": "http://schema.org/OutOfStock",
		"itemCondition": "http://schema.org/NewCondition"
	}
}

It works fine when the price is lower case and Assert.IsTrue passes. However when price starts with a captial P, the Assert.IsTrue fails as both HasValue1 and HasValue2 are false on the offer.

Expected behaviour

I think it should pick up the price irrelevant of the case, as the following website says it is valid schema.org: https://validator.schema.org/

Schema objects

https://schema.org/Offer

@dermotblairca dermotblairca added the bug Issues describing a bug or pull requests fixing a bug. label Dec 21, 2022
@dermotblairca dermotblairca changed the title If a json property starts with a capital, it is not deserialized If a json property starts with a capital letter, it is not deserialized Dec 21, 2022
@dermotblairca dermotblairca changed the title If a json property starts with a capital letter, it is not deserialized If a json property starts with a capital letter, it is not included in the deserialized object Dec 21, 2022
@Turnerj
Copy link
Collaborator

Turnerj commented Dec 23, 2022

This one I'm more on the fence about - on one hand, you're right, the validator says it is fine. On the other, should we be potentially looking at more broad case insensitive parsing? I mean, while your example is the first letter, maybe we should be every letter of a property. Do we then look at enum values too and parse them case insensitively?

Schema.org doesn't specify any case sensitivity requirements that I could find so maybe the answer is we shouldn't be case sensitive either.

@RehanSaeed - I'm curious what you think when you're available to look at this.

@RehanSaeed
Copy link
Owner

We should make what we accept more open and accept case insensitive JSON as you suggest. We'd happily accept a PR to that effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug or pull requests fixing a bug.
Projects
None yet
Development

No branches or pull requests

3 participants