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

Support decimal precision for Document.FromJson and ToJson by using System.Text.Json instead of LitJson #3447

Open
wants to merge 1 commit into
base: v4-development
Choose a base branch
from

Conversation

ashovlin
Copy link
Member

Description

Before

Currently, Document.FromJson and Document.ToJson in DynamoDBv2 use LitJson for JSON handling.

This does not support decimal, as the first numeric type it matches to here is double.

if (number.IndexOf ('.') != -1 ||
number.IndexOf ('e') != -1 ||
number.IndexOf ('E') != -1) {
double n_double;
if (Double.TryParse(number, NumberStyles.Any, CultureInfo.InvariantCulture, out n_double))
{
token = JsonToken.Double;
token_value = n_double;
return;
}
}

This is leading to a loss of precision for decimal values, see the linked issues.

After

This proposes to address this by replacing LitJson in these code paths with System.TextJson.

  • We want to do this anyway as long term we'd like to remove the embedded copy of LitJson from AWSSDK.Core.

While this addresses the reported issue, we still need to look at:

  • Is this causing a regression for any other numeric values or types, or even non-numeric types?
  • Is it handling comments, malformed JSON, etc. the same way?

Motivation and Context

#1555 , #1039

Testing

  • Ran DynamoDBv2 sln tests locally
  • PENDING dry-run

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

…f LitJson. This supports additional precision for decimal values.
@ashovlin ashovlin changed the title Support decimial precision for Document.FromJson and ToJson by using System.Text.Json instead of LitJson Support decimal precision for Document.FromJson and ToJson by using System.Text.Json instead of LitJson Aug 19, 2024
Comment on lines -92 to -98
// Trim everything before the first '{' character
var jsonIndex = FirstIndex(sb, '{');
if (jsonIndex > 0)
sb.Remove(0, jsonIndex);

var jsonText = sb.ToString();
return jsonText;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is included, didn't port it over for now.

""Name"" : ""Alan"" ,
""Age"" : 31,
""CompanyName"" : ""Big River"" ,
""CurrentStatus"" : ""Active""
""CurrentStatus"" : ""Active"",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was passing before despite the missing comma, but STJ throws an exception now.

@dscpinheiro dscpinheiro marked this pull request as ready for review September 13, 2024 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant