Restores float <-> decimal conversions in the binary reader#905
Merged
Restores float <-> decimal conversions in the binary reader#905
Conversation
While the documentation for `IonReader#doubleValue` and `decimalValue` indicates that those methods will throw an exception when then the current value's `IonType` is not `FLOAT` or `DECIMAL` respectively, versions of `ion-java` up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the previous behavior. This PR restores the previously supported numeric type coercions for `doubleValue`, `decimalValue`, and `bigDecimalValue` and adds unit tests to prevent future regressions.
popematt
approved these changes
Jul 1, 2024
Contributor
popematt
left a comment
There was a problem hiding this comment.
Couple of formatting nitpicks, but otherwise good.
| value = scalarConverter.getBigDecimal(); | ||
| scalarConverter.clear(); | ||
| } else if (valueTid.type == IonType.FLOAT) { | ||
| scalarConverter.addValue(doubleValue()); |
Contributor
There was a problem hiding this comment.
Nit—Indentation is off here.
| static Stream<InputStream> testData() { | ||
| byte[] textData = "$ion_1_0 42 42e0 42.0".getBytes(StandardCharsets.UTF_8); | ||
| byte[] binaryData = { | ||
| // Version marker 1.0 |
Contributor
There was a problem hiding this comment.
Nit—I think we're trying to use a single level of indentation for cases like this.
Contributor
Author
There was a problem hiding this comment.
How odd--this is what IntelliJ's auto-formatter chose, but I can't imagine why. Fixed!
tgregg
approved these changes
Jul 1, 2024
Contributor
tgregg
left a comment
There was a problem hiding this comment.
+1 to Matt's comments, but looks good.
linlin-s
pushed a commit
that referenced
this pull request
Jul 3, 2024
While the documentation for `IonReader#doubleValue` and `decimalValue` indicates that those methods will throw an exception when then the current value's `IonType` is not `FLOAT` or `DECIMAL` respectively, versions of `ion-java` up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the previous behavior. This PR restores the previously supported numeric type coercions for `doubleValue`, `decimalValue`, and `bigDecimalValue` and adds unit tests to prevent future regressions.
linlin-s
pushed a commit
that referenced
this pull request
Jul 3, 2024
While the documentation for `IonReader#doubleValue` and `decimalValue` indicates that those methods will throw an exception when then the current value's `IonType` is not `FLOAT` or `DECIMAL` respectively, versions of `ion-java` up to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the previous behavior. This PR restores the previously supported numeric type coercions for `doubleValue`, `decimalValue`, and `bigDecimalValue` and adds unit tests to prevent future regressions.
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.
While the documentation for
IonReader#doubleValueanddecimalValueindicates that those methods will throw an exception when then the current value'sIonTypeis notFLOATorDECIMALrespectively, versions ofion-javaup to and including v1.10.5 would quietly coerce numeric values to the requested type. The new binary reader implementation hewed to the documentation's stated contract, but this ended up being a breaking change for a small number of users who depended on the undocumented behavior.This PR restores the previously supported numeric type coercions for
doubleValue,decimalValue, andbigDecimalValueand adds unit tests to prevent future regressions. It also replaces uses of the deprecated$buildDiraccessor inbuild.gradle.ktswith the now-recommended${layout.buildDirectory}.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.