-
Notifications
You must be signed in to change notification settings - Fork 9.1k
v3.1.2: Provide guidance on null in XML. #4612
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
Conversation
There really isn't a native `null` type in XML, as both elements and attributes that are empty have an empty string value. We also need to leave the behavior implementation-defined for compatibility. However, the `xsi:nil` attribute is the closest thing to a `null` element. Attributes are harder, and the best I can come up with is letting `null` behave the same as an omitted attribute for the purpose of serialization.
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.
@handrews > we could forbid type: [..., "null"] or type: "null" with xml: {nodeType: "attribute"} and leave the behavior with the deprecated xml: {attribute: true} unchanged.
This seems like reasonable constraint.
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.
+1, just a doubt on punctuation
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.
Thanks, this is a good addition
@handrews Will you create the same change for 3.2? Can we link the PRs together when you do? |
@lornajane removing JSON examples was just 3.2, although I would not object to removing them in 3.1.2 if folks want. I was thinking of adding this to PR #4592 as otherwise it will be a mess of git conflicts. Alternatively, we could wait for #4592 to merge and then I'll port this (and other XML-related 3.1.2 changes). I was going to do one big 3.1.2->3.2 sync PR with individual commits (like I did last time around for the final sync PRs), but I can do this one separately if needed. |
Fixes:
There really isn't a native
null
type in XML, as both elements and attributes that are empty have an empty string value.We also need to leave the behavior implementation-defined for compatibility.
However, attaching the
xsi:nil=true
attribute to an empty element is the closest thing to anull
element.Attributes are harder, and the best I can come up with is letting
null
behave the same as an omitted attribute for the purpose of serialization. This means that for round-tripping, whether a missing attribute is parsed into anull
property or as an omitted property depends on whether the schema allowsnull
.This attribute behavior is a bit weird, but I can't come up with anything else that has a hope of round-tripping propery, and we can't outright forbid
null
in a patch release. If PR #4592 is accepted, we could forbidtype: [..., "null"]
ortype: "null"
withxml: {nodeType: "attribute"}
and leave the behavior with the deprecatedxml: {attribute: true}
unchanged.So I guess the question here is whether the attribute guidance is more confusing than helpful. The fact that we got asked about it suggests that we ought to say something, though.