-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix #221 Support alternate radixes for numeric values #5317
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
When writing numeric values as strings, we would like to support alternative to base-10 representations. Let's add it via @jsonformat annotation. Whenever the shape is STRING and pattern is a number, we serialize/deserialize annotated properties using the specified alternative radix.
src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfig.java
Outdated
Show resolved
Hide resolved
...n/java/com/fasterxml/jackson/databind/deser/std/FromStringWithRadixToNumberDeserializer.java
Show resolved
Hide resolved
|
I based the change on the 2.x branch. I understand that the latest release is 2.20 and this should is a backwards compatible change, so it should be done against the next minor version (2.21), but I could not find it as one of the remote branches. Also addressing the comments now @pjfanning, thank you. |
src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializer.java
Outdated
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/DeserializationConfig.java
Outdated
Show resolved
Hide resolved
pjfanning
left a comment
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.
some changes requested
| return Long.parseLong(text, radix); | ||
| } else { | ||
| ctxt.reportInputMismatch(handledType, | ||
| "Trying to deserialize a non-whole number with NumberToStringWithRadixSerializer"); |
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.
I considered explicitly throwing here, but this seemed like a more common way to indicate an error.
src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializer.java
Outdated
Show resolved
Hide resolved
|
Impressive PR! One big(ger) question/concern I have is the addition of but I realize there's the problem of changing radix for ALL integral types. Perhaps that could be tackled by adding actual I'd just not want to force it through all machinery via |
|
Fails CI; probably uses some Java 17 language feature (2.x still has Java 8 baseline; 3.x has 17) |
|
Just want to preface by saying this is not a final change but more of an outline where I am still using A few comments and questions:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<argLine>
-javaagent:${org.mockito:mockito-core:jar}
-Xshare:off
</argLine>
</configuration>
</plugin>However, the solution only works with newer mockito jars. The I think we have 2 options here:
|
|
Quick note on: I think it's |
|
Will file an issue and try to address it! Please let me know what you think about the other questions/concerns once you get the chance. |
|
FasterXML/jackson-annotations#316 - made the pull request. Would it make sense to make the change to annotations and go with the initial approach that failed? |
|
Annotation stuff now fixed, should be serializable. |
|
Fudge! Was not supposed to merge; need to revert ASAP |
|
I do not know how, but somehow I managed to merge this -- not via UI. So had to revert via #5373. Not sure how to re-create PR... sorry. I hate git sometimes. Today is such a day. :-( |
|
I can just try and get it from my local branch. Should I create a new PR? |
|
New PR sounds good @tiger9800 |
|
I think the changes are still in. Though the change is incomplete, and I will finish it in with a new PR that starts using radix property of |
|
Just my opinion but I would prefer if this was removed from 2.x and only a 3.x target considered. |
|
Do you mean the new pull request or should we revert the changes from this one in 2.x? |
|
Agree wrt this targeting 3.1. |
New PR with changes targeting |
|
I see it in my 2.x local branch after pulling, but I guess there is a different 2.x branch somewhere. I will make the new PR targeting 3.x once the annotation change is merged. |
|
@tiger9800 Just merged annotations changes -- should be available via |
Main Github repo has |
When writing numeric values as strings, we would like to support alternative to base-10 representations. Let's add it via
@JsonFormatannotation. Whenever the shape is STRING and pattern is a number, we serialize/deserialize annotated properties using the specified alternative radix.