-
Notifications
You must be signed in to change notification settings - Fork 351
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
Nullable attribute missing for collection type reference #2034
base: release-7.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR makes the nullable attribute required for collections in both XML and JSON. However, I think the nullable attribute requirement only applies to XML -- I believe it is valid in JSON to have a collection valued property that does not specify the nullable attribute.
This means that the factoring is a bit off. Rather than deciding in the common serialization classes whether the nullable attribute is required, we should pass down the information required for the xml serializer to decide whether or not the null should be written.
@@ -311,7 +311,8 @@ public void WriteNavigationPropertyInComplexType() | |||
}, | |||
""Addresses"": { | |||
""$Collection"": true, | |||
""$Type"": ""DefaultNs.Address"" | |||
""$Type"": ""DefaultNs.Address"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nullable facet is required for collections in XML, but I don't think it's required in JSON.
Which means our factoring is a bit off -- we shouldn't have code in the serializer to determine whether the null needs to be written. Instead, we should pass down the information that lets the XML serializer decide whether or not to write the null value (i.e., whether or not we are writing a structural property).
@@ -653,7 +656,7 @@ private void ProcessReferentialConstraint(IEdmReferentialConstraint element) | |||
} | |||
} | |||
|
|||
private void ProcessFacets(IEdmTypeReference element, bool inlineType) | |||
private void ProcessFacets(IEdmTypeReference element, bool inlineType, bool nullableAttributeRequiredForCollection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the call "chain" is
EdmModelCsdlSerializationVisitor.{ProcessStructuralProperty|ProcessTerm|ProcessCollectionType|...)
EdmModelCsdlSerializationVisitor.ProcessFacets ->
EdmModelCsdlSchemaWriter.WriteNullableAttribute
and EdmModelCsdlSchemaWriter is abstract (one concrete subclass for XML, one for JSON)
And yes, it is true that only ProcessStructuralProperty is passing in true. But that doesn't describe the behavior of ProcessFacets which is : instruct the writer to write the property for a collection type (-reference) even if it is false (which otherwise dosn't get written). The name is based on what the method does, not on how and when it is called.
But I don't have a strong opinion. Happy to change it if you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss -- my concern is that, as I understand it, a component that should be format-agnostic (EdmModelCsdlSerializationVistor) would be making the decision of whether to write the nullable attribute or not based on the format (write for xml, not for json). ideally, we wouldn't be making format-specific decisions in these common classes, they would all be made in the format-specific implementations.
@@ -384,10 +384,18 @@ internal override void WriteEnumMemberElementHeader(IEdmEnumMember member) | |||
/// 7.2.1 Nullable, A Boolean value specifying whether a value is required for the property. | |||
/// </summary> | |||
/// <param name="reference">The Edm type reference.</param> | |||
internal override void WriteNullableAttribute(IEdmTypeReference reference) | |||
/// <param name="alwaysWrite">Specifies if the attribute is always written or not if the value is the default value. | |||
internal override void WriteNullableAttribute(IEdmTypeReference reference, bool alwaysWrite) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is the alwaysWrite
parameter ever set to true and why? what determines whether it should be set true or false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gets called from EdmModelCsdlSerializationVisitor.ProcessFacets
And that method tests if the property is of a collection type and if the serializer wants to always serialize the nullable attributes for collection (which is true for XML, false for JSON)
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
""test02"": { | ||
""$Collection"": true, | ||
""$Type"": ""Edm.Decimal"", | ||
""$Nullable"": false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be written in this case for json csdl, right?
Issues
*This pull request fixes issue #2028
Description
Added parameter to WriteNullableAttribute to indicate if the property should be written always or depending on the default value.
Checklist (Uncheck if it is not completed)
Additional work necessary
If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.