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

Exception thrown The JSON value could not be converted to Schema.NET.IValues #389

Open
dermotblairca opened this issue Feb 9, 2022 · 5 comments
Labels
bug Issues describing a bug or pull requests fixing a bug.

Comments

@dermotblairca
Copy link
Contributor

dermotblairca commented Feb 9, 2022

Describe the bug

The following exception is thrown when trying to parse the Product json in the following Walmart.com URL: https://www.walmart.com/ip/Air-Wick-Plug-in-Scented-Oil-Warmer-2-ct-White-color-Air-Freshener-Essential-Oils/14284640?athbdg=L1600
"System.Text.Json.JsonException: 'The JSON value could not be converted to Schema.NET.IValues. Path: $.name | LineNumber: 0 | BytePositionInLine: 29.'"
This validates fine on validtor.schema.org: https://validator.schema.org/#url=https%3A%2F%2Fwww.walmart.com%2Fip%2FAir-Wick-Plug-in-Scented-Oil-Warmer-2-ct-White-color-Air-Freshener-Essential-Oils%2F14284640%3Fathbdg%3DL1600

In my code, I am getting the Product json from the Script element and then calling the following:
var product = SchemaSerializer.DeserializeObject<Schema.NET.Product>(json);

I was also able to reproduce this by downloading the Schema.Net source and adding the following test to the ProductTest.cs file (as shown in Steps to reproduce):

Steps to reproduce

Add the following to ProductTest.cs file and run the test:

[Fact]
public void Deserializing_ProductJsonLd_ReturnsProduct2()
{
	try
	{
		var json2 = "{\"@context\":\"https://schema.org\",\"@type\":\"Product\",\"image\":\"https://i5.walmartimages.com/asr/f5ba1901-86b6-4acc-8817-4ea6db4a2c4f.165575619ff93ed6562d6c7485bb24cf.jpeg\",\"name\":\"AirWickPluginScentedOilWarmer,2ct,Whitecolor,AirFreshener,EssentialOils\",\"sku\":\"14284640\",\"gtin13\":\"062338780481\",\"description\":\"Enhanceyourhome’sscentwithAirWickScentedOilRefillsinfusedwith100%naturalessentialoils.AirWickPlug-InScentedOilfragrancesareinfusedwithnaturalessentialoilsandblendedtobringtheessenceofnatureintoyourhome.Justplugin,chooseyourfragrancesetting,andenjoyacontinuousreleaseoffreshnessforupto60days(basedonlowsetting).OurlatestAirWickscentedoilwarmerreleasesfragranceupwardsandoutwards,reachingeverycorneroftheroomforaconsistentfragranceexperience.TheAirWickScentedOilwarmeralsoallowsyoutochoosebetween5fragrancesettingsforjusttherightamountoffragrance.Itcontinuouslydiffusesandcarefullyblendsfragrancethroughoutyourhome,office,oranyspace.\",\"model\":\"6233878048\",\"brand\":{\"@type\":\"Thing\",\"name\":\"AirWick\"},\"aggregateRating\":{\"@type\":\"AggregateRating\",\"ratingValue\":4.6,\"bestRating\":5,\"reviewCount\":307},\"offers\":{\"@type\":\"Offer\",\"url\":\"https://www.walmart.com/ip/Air-Wick-Plug-in-Scented-Oil-Warmer-2-ct-White-color-Air-Freshener-Essential-Oils/14284640\",\"priceCurrency\":\"USD\",\"price\":5.01,\"availability\":\"https://schema.org/InStock\",\"itemCondition\":\"https://schema.org/NewCondition\",\"availableDeliveryMethod\":\"https://schema.org/OnSitePickup\"},\"review\":[{\"@type\":\"Review\",\"name\":\"CoverstheWholeRoom\",\"datePublished\":\"February8,2021\",\"reviewBody\":\"IloveAirWickPlug-InScentedwarmersbecausetheylastalongtimeIhavetriedseveralscentsandtheyallsmellamazing.Thescentwillcoverthewholeroomfromcornertocorner.IwillcontinuetopurchasetheAirWickScentedOilWarmer\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"gghardin\"}},{\"@type\":\"Review\",\"name\":\"ExcellentValue!\",\"datePublished\":\"May13,2013\",\"reviewBody\":\"AirWickismygotoscentbrand.ThepricesarecheaperthanGladeandFebreezeanditdoesjustasgoodofajob.Ilovethevarietyofscentsandthiswarmerdoesagreatjobfilteringthescentthruthehouse.I'dbuyagainespeciallyatthisprice!\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"xtinerobertson\"}},{\"@type\":\"Review\",\"name\":\"Affordablepluginsfilltheroomwithcozyscents\",\"datePublished\":\"March19,2021\",\"reviewBody\":\"ThesepluginsareaffordableandworkwithstandardAirWickscentrefills.Igotseveralforallovermyapartment.EventheclosetsmellslikeHawaiinow.Onthehighestsetting,Igotabouttwoandhalfweeksoutofonerefill.Ihavethemallsetto3now,andI'mestimatingthey'lllastaboutamonthtosixweeks.Muchlessexpensivethansomeotherscentwarmersouttherebutworksjustaswell.Asfortherefills,checkoutvanillaandpinkpapaya.It'smyfavorite!\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"Kris\"}},{\"@type\":\"Review\",\"name\":null,\"datePublished\":\"July10,2021\",\"reviewBody\":\"IlovethesmelloftheseandtheyIlovethesmelloftheseandtheyreawesomebecauseIdonthavetosmellmyneighborsmokeinherdrugs\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"James\"}},{\"@type\":\"Review\",\"name\":\"greatprice\",\"datePublished\":\"July14,2016\",\"reviewBody\":\"Thisisasuperpricefortheseplug-inwarmers.Theyalsoacceptthedollar-storeversionplug-ins,notjusttheAirWickbrand.Thesedon'thaveanyadjustmentsforairflowwhichtheonesinthemoreexpensiveAirWickwarmer-scentkitshave.\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"therica\"}},{\"@type\":\"Review\",\"name\":\"Greatpriceforthese\",\"datePublished\":\"May29,2013\",\"reviewBody\":\"ThisisagreatvalueandAirWickhasawidevarietyoffunscents.\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"Deru\"}},{\"@type\":\"Review\",\"name\":\"ValueforMoney\",\"datePublished\":\"June3,2013\",\"reviewBody\":\"Thepricesarecheaperandqualityisgreatwithwiderangevarietyofscents.\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"rktreviews\"}},{\"@type\":\"Review\",\"name\":\"Ihavetheseallaroundmyhome.Lovethem\",\"datePublished\":\"July20,2021\",\"reviewBody\":\"Ihavetheseallaroundmyhome.Lovethem\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"MorgantownDad\"}},{\"@type\":\"Review\",\"name\":\"Easytouse\",\"datePublished\":\"June8,2021\",\"reviewBody\":\"Easytouse.Keepsthehousesmellingnice.\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":5,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"Yokom\"}},{\"@type\":\"Review\",\"name\":null,\"datePublished\":\"August6,2021\",\"reviewBody\":\"IdidnotlikeIdidnotgetmyitemIwanted\",\"reviewRating\":{\"@type\":\"Rating\",\"worstRating\":1,\"ratingValue\":1,\"bestRating\":5},\"author\":{\"@type\":\"Thing\",\"name\":\"Anitra\"}}]}";
		var product = SchemaSerializer.DeserializeObject<Product>(json2);
	}
	catch (Exception ex)
	{
		var message = ex.Message;
		throw;
	}
}

Expected behaviour

The JSON should be deserialized to an object of the Product class.

Schema objects

https://schema.org/Product

The formatted JSON of the Product in the Walmart.com URL is the following:

{
	"@context": "https://schema.org",
	"@type": "Product",
	"image": "https://i5.walmartimages.com/asr/f5ba1901-86b6-4acc-8817-4ea6db4a2c4f.165575619ff93ed6562d6c7485bb24cf.jpeg",
	"name": "Air Wick Plug in Scented Oil Warmer, 2 ct, White color, Air Freshener, Essential Oils",
	"sku": "14284640",
	"gtin13": "062338780481",
	"description": "Enhance your home’s scent with Air Wick Scented Oil Refills infused with 100% natural essential oils. Air Wick Plug-In Scented Oil fragrances are infused with natural essential oils and blended to bring the essence of nature into your home. Just plug in, choose your fragrance setting, and enjoy a continuous release of freshness for up to 60 days (based on low setting). Our latest Air Wick scented oil warmer releases fragrance upwards and outwards, reaching every corner of the room for a consistent fragrance experience. The Air Wick Scented Oil warmer also allows you to choose between 5 fragrance settings for just the right amount of fragrance. It continuously diffuses and carefully blends fragrance throughout your home, office, or any space.",
	"model": "6233878048",
	"brand": {
		"@type": "Thing",
		"name": "Air Wick"
	},
	"aggregateRating": {
		"@type": "AggregateRating",
		"ratingValue": 4.6,
		"bestRating": 5,
		"reviewCount": 307
	},
	"offers": {
		"@type": "Offer",
		"url": "https://www.walmart.com/ip/Air-Wick-Plug-in-Scented-Oil-Warmer-2-ct-White-color-Air-Freshener-Essential-Oils/14284640",
		"priceCurrency": "USD",
		"price": 5.01,
		"availability": "https://schema.org/InStock",
		"itemCondition": "https://schema.org/NewCondition",
		"availableDeliveryMethod": "https://schema.org/OnSitePickup"
	},
	"review": [
		{
			"@type": "Review",
			"name": "Covers the Whole Room",
			"datePublished": "February 8, 2021",
			"reviewBody": "I love AirWick Plug-In Scented warmers because they last a long time I have tried several scents and they all smell amazing. The scent will cover the whole room from corner to corner. I will continue to purchase the AirWick Scented Oil Warmer",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "gghardin"
			}
		},
		{
			"@type": "Review",
			"name": "Excellent Value!",
			"datePublished": "May 13, 2013",
			"reviewBody": "Air Wick is my go to scent brand. The prices are cheaper than Glade and Febreeze and it does just as good of a job. I love the variety of scents and this warmer does a great job filtering the scent thru the house. I'd buy again especially at this price!",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "xtinerobertson"
			}
		},
		{
			"@type": "Review",
			"name": "Affordable plugins fill the room with cozy scents",
			"datePublished": "March 19, 2021",
			"reviewBody": "These plug ins are affordable and work with standard Air Wick scent refills. I got several for all over my apartment. Even the closet smells like Hawaii now. On the highest setting, I got about two and half weeks out of one refill. I have them all set to 3 now, and I'm estimating they'll last about a month to six weeks. Much less expensive than some other scent warmers out there but works just as well. As for the refills, check out vanilla and pink papaya. It's my favorite!",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "Kris"
			}
		},
		{
			"@type": "Review",
			"name": null,
			"datePublished": "July 10, 2021",
			"reviewBody": "I love the smell of these and theyI love the smell of these and theyre awesome because I dont have to smell my neighbor smoke in her drugs",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "James"
			}
		},
		{
			"@type": "Review",
			"name": "great price",
			"datePublished": "July 14, 2016",
			"reviewBody": "This is a super price for these plug-in warmers.  They also accept the dollar-store version plug-ins, not just the AirWick brand.  These don't have any adjustments for air flow which the ones in the more expensive AirWick warmer-scent kits have.",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "therica"
			}
		},
		{
			"@type": "Review",
			"name": "Great price for these",
			"datePublished": "May 29, 2013",
			"reviewBody": "This is a great value and Air Wick has a wide variety of fun scents.",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "Deru"
			}
		},
		{
			"@type": "Review",
			"name": "Value for Money",
			"datePublished": "June 3, 2013",
			"reviewBody": "The prices are cheaper and quality is great with wide range variety of scents .",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "rktreviews"
			}
		},
		{
			"@type": "Review",
			"name": "I have these all around my home.  Love them",
			"datePublished": "July 20, 2021",
			"reviewBody": "I have these all around my home.  Love them",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "MorgantownDad"
			}
		},
		{
			"@type": "Review",
			"name": "Easy to use",
			"datePublished": "June 8, 2021",
			"reviewBody": "Easy to use.  Keeps the house smelling nice.",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 5,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "Yokom"
			}
		},
		{
			"@type": "Review",
			"name": null,
			"datePublished": "August 6, 2021",
			"reviewBody": "I did not like I did not get my item I wanted",
			"reviewRating": {
				"@type": "Rating",
				"worstRating": 1,
				"ratingValue": 1,
				"bestRating": 5
			},
			"author": {
				"@type": "Thing",
				"name": "Anitra"
			}
		}
	]
}
@dermotblairca dermotblairca added the bug Issues describing a bug or pull requests fixing a bug. label Feb 9, 2022
@RehanSaeed
Copy link
Owner

RehanSaeed commented Feb 9, 2022

I managed to get a minimal repro of the bug:

[Fact]
public void Deserializing_ProductJsonLd_ReturnsProduct2()
{
    var json = "{\"@context\":\"https://schema.org\",\"@type\":\"Review\",\"name\":null}";
    var product = SchemaSerializer.DeserializeObject<Review>(json);
}

Looks like the null value in the name is causing the issue.

@dermotblairca
Copy link
Contributor Author

Thanks for the prompt reply @RehanSaeed

@dermotblairca
Copy link
Contributor Author

Would you have an idea when this might be fixed @RehanSaeed? Thanks in advance.

@RehanSaeed
Copy link
Owner

I put together this PR with some unit tests that repro this problem. The exception seems to be thrown deep in the bowels of System.Text.Json and I'm not certain what to do here. @Turnerj might be able to help.

@dermotblairca
Copy link
Contributor Author

Thanks again @RehanSaeed

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

2 participants