GH-2270: Properly process objects passed in as xsd:string literals.#2301
Merged
rvesse merged 1 commit intoapache:mainfrom Feb 29, 2024
Merged
Conversation
rvesse
approved these changes
Feb 28, 2024
Member
rvesse
left a comment
There was a problem hiding this comment.
LGTM, can you please squash into a single commit?
Contributor
Author
|
Of course. For future reference, you can enable that within Pull Request themselves to remove manual steps, which can be potentially error prone in my experience. I'll also rebase the branch too while I'm at it. |
39d55ec to
26e0207
Compare
kinow
approved these changes
Feb 28, 2024
Member
|
Please use "squash and merge" with care - the commit message isn't going to be great (requires human checking) and the merge is often being done by a different person to the contributor. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub issue resolved #2270
Pull request Description:
As illustrated in the sample code on the linked issue, when creating literal nodes of xsd:string type we are not converting the given objects to Strings but rather are leaving them as the original classes. Instead of UUIDs, the same effect can be made if passed Integers, Floats or any other object type.
NodeFactory.createLiteralByValue(UUID.randomUUID(), XSDDatatype.XSDstring); NodeFactory.createLiteralByValue(9, XSDDatatype.XSDstring); NodeFactory.createLiteralByValue(9.99f, XSDDatatype.XSDstring);What's interesting is that for numeric types, this isn't the case and if passing a (valid) string to numeric type everything works as expected.
NodeFactory.createLiteralByValue("9", XSDDatatype.XSDint); NodeFactory.createLiteralByValue("9.99", XSDDatatype.XSDfloat);The fix is relatively simple. When processing the canonised form (using the "cannonicalise" (sic) method) of the XSDBaseStringType the original value is being returned. By contrast, if you look at the equivalent XSDBaseNumericType the value is converted into the appropriate type.
To that end, I've added some tests to illustrate this by creating both string and numerical literal nodes passing in differing classes.
By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.
See the Apache Jena "Contributing" guide.