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

The JSON property name for 'Schema.NET.IHospital.OpeningHours' collides with another property. #603

Open
fewless2019 opened this issue Jun 6, 2023 · 5 comments
Labels
bug Issues describing a bug or pull requests fixing a bug.

Comments

@fewless2019
Copy link

fewless2019 commented Jun 6, 2023

Describe the bug

Can not serialize a schema.net.Physician while using schema.net.MedicalWebPage

Properties with the same name.

hospital ->CivicStructureAndEmergencyServiceAndMedicalOrganization ->

[JsonPropertyName("openingHours")]
[JsonPropertyOrder(307)]
[JsonConverter(typeof(ValuesJsonConverter))]
public override OneOrMany<string> OpeningHours { get; set; }

Physician-> MedicalBusinessAndMedicalOrganization -> LocalBusinessAndOrganization ->

[JsonPropertyName("openingHours")]
[JsonPropertyOrder(238)]
[JsonConverter(typeof(ValuesJsonConverter))]
public OneOrMany<string> OpeningHours { get; set; }

Steps to reproduce

//Site Default
MedicalAudience medicalAudience = new MedicalAudience()
{
	RequiredMinAge = 0,
	RequiredMaxAge = 21,
	SuggestedMinAge = 0,
	SuggestedMaxAge = 21,
	SuggestedGender = "All genders"
};

MedicalWebPage website = new MedicalWebPage()
{
	MedicalAudience = medicalAudience
};


Physician physician = new Physician()
{
	Name = doctorProfilePage.DisplayName,
	Description = doctorProfilePage.CurrentPage.SeoSettings.Description,
};

if (Uri.IsWellFormedUriString(doctorProfilePage.Image, UriKind.Absolute))
{
	Uri outUri;

	if (Uri.TryCreate(doctorProfilePage.Image, UriKind.RelativeOrAbsolute, out outUri))
	{
		ImageObject image = new ImageObject()
		{
			ThumbnailUrl = outUri,
			Url = outUri
		};

		physician.Image = image;
		physician.Photo = image;
		website.Image = image;
	}
}

physician.Address = doctorProfilePage.GetSchemaAddress();
physician.Telephone = doctorProfilePage.GetSchemaPhone();
physician.Identifier = doctorProfilePage.ProfileId.ToString();
physician.Id = baseUri;
					
//website.MainEntity = mainHospital;
website.About = physician;

return website.ToHtmlEscapedString()  //Fails here. on ToHtmlEscapedString

Stack trace

System.InvalidOperationException: The JSON property name for 'Schema.NET.IHospital.OpeningHours' collides with another property.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerPropertyNameConflict(Type type, String propertyName) 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.AddProperty(JsonPropertyInfo jsonPropertyInfo, PropertyHierarchyResolutionState& state) 
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.AddMembersDeclaredBySuperType(JsonTypeInfo typeInfo, Type currentType, Boolean shouldCheckMembersForRequiredMemberAttribute, PropertyHierarchyResolutionState& state) 
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.PopulateProperties(JsonTypeInfo typeInfo) 
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.CreateTypeInfoCore(Type type, JsonConverter converter, JsonSerializerOptions options) 
at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetTypeInfo(Type type, JsonSerializerOptions options) 
at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type) 
at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context) 
--- End of stack trace from previous location --- 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|161_0() 
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure() 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.ConfigureProperties() 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure() 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo.g__ConfigureSynchronized|161_0() 
at System.Text.Json.JsonSerializer.Serialize(Utf8JsonWriter writer, Object value, Type inputType, JsonSerializerOptions options) 
at Schema.NET.ValuesJsonConverter.WriteObject(Utf8JsonWriter writer, Object value, JsonSerializerOptions options) in /_/Source/Common/ValuesJsonConverter.cs:line 184
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) 
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.GetMemberAndWriteJson(Object obj, WriteStack& state, Utf8JsonWriter writer) 
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryWrite(Utf8JsonWriter writer, T value, JsonSerializerOptions options, WriteStack& state) 
at System.Text.Json.Serialization.JsonConverter`1.TryWrite(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) 
at System.Text.Json.Serialization.JsonConverter`1.WriteCore(Utf8JsonWriter writer, T& value, JsonSerializerOptions options, WriteStack& state) 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed, Boolean isInvokedByPolymorphicConverter) 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.SerializeAsObject(Utf8JsonWriter writer, Object rootValue, Boolean isInvokedByPolymorphicConverter) 
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed, Boolean isInvokedByPolymorphicConverter) 
at System.Text.Json.JsonSerializer.WriteString[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo) 
at Schema.NET.Thing.ToString() in /_/Source/Common/Thing.Partial.cs:line 23 
at SeattleChildrens.Features.SchemaExtensions.GenerateSchema(IHtmlHelper helper, IWebPage viewModel) in C:\repos\SeattleChildrens.orgCore\SeattleChildrens.Features\Infrastructure\Extensions\SchemaExtensions.cs:line 593

Properties with the same Name
hospital ->CivicStructureAndEmergencyServiceAndMedicalOrganization ->

[JsonPropertyName("openingHours")]
[JsonPropertyOrder(307)]
[JsonConverter(typeof(ValuesJsonConverter))]
public override OneOrMany<string> OpeningHours { get; set; }

Physician-> MedicalBusinessAndMedicalOrganization -> LocalBusinessAndOrganization ->

[JsonPropertyName("openingHours")]
[JsonPropertyOrder(238)]
[JsonConverter(typeof(ValuesJsonConverter))]
public OneOrMany<string> OpeningHours { get; set; }

Expected behaviour

Unique names and ability to serialize.

Schema objects

schema.net.Physician
schema.net.MedicalWebPage

@fewless2019 fewless2019 added the bug Issues describing a bug or pull requests fixing a bug. label Jun 6, 2023
@Turnerj
Copy link
Collaborator

Turnerj commented Jun 8, 2023

Hi @fewless2019 - I can't recreate the problem you've describe by using the steps you've mentioned. Can you tell me the version of .NET you're using, whether you're pulling in your own version of System.Text.Json (and what version that is), and also have a look over the steps to reproduce that you've provided.

Based on the exception message, I don't think the problem is to do with the Physician inheritance but the Hospital inheritance. Specifically CivicStructureAndEmergencyServiceAndMedicalOrganization has OpeningHours and so does LocalBusinessAndOrganizationAndPlace. And even then, the exception refers to the interface IHospital, not the implementation.

The strange part though is these combined types have several properties that are overridden, not just OpeningHours and I don't see anything special about OpeningHours in terms of how it is defined in Schema.NET nor any reference in your steps to reproduce.

@fewless2019
Copy link
Author

fewless2019 commented Jun 8, 2023 via email

@fewless2019
Copy link
Author

fewless2019 commented Jun 8, 2023 via email

@kirk-marple
Copy link
Contributor

Just ran across this issue, since I saw a similar issue serializing 'MedicalStudy'.

I'm getting this error:
The JSON property name for 'Schema.NET.IDrug.Funding' collides with another property.

This is using .NET 8.0 version of System.Text.Json.

@kirk-marple
Copy link
Contributor

Looks like my serialization issue was due to 'Drug' being a subclass of both Product and Substance, and the 'Funding' property is defined in both places.

Not sure how Schema.NET is supposed to handle these kinds of situations?

I had to create a private version of the library, and remove 'Product' from the JSON-LD file to get it working.

cc: @Turnerj @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

3 participants