-
-
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
Open
tiger9800
wants to merge
9
commits into
FasterXML:2.x
Choose a base branch
from
tiger9800:2.x
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
722182b
Fix #221 Support alternate radixes for numeric values
tiger9800 6096e27
Fix #221 - address PR comments
tiger9800 7a211db
Fix #221 - address PR comments
tiger9800 5db64fa
Fix #221 - address PR comments
tiger9800 229d691
Fix #221 - add test
tiger9800 7dabb4b
Fix #221 - address PR comments
tiger9800 49424e5
Merge branch '2.x' into 2.x
cowtowncoder 5599e79
Fix #221 - wire default radix via ConfigOverrides
tiger9800 ac1c279
Merge branch '2.x' into 2.x
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
50 changes: 50 additions & 0 deletions
50
...ava/com/fasterxml/jackson/databind/deser/std/FromStringWithRadixToNumberDeserializer.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.fasterxml.jackson.databind.deser.std; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonToken; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
|
||
/** | ||
* Deserializer used to deserialize string that represent number under in specific radix (base). | ||
*/ | ||
tiger9800 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public class FromStringWithRadixToNumberDeserializer | ||
extends StdDeserializer<Number> { | ||
private final int radix; | ||
|
||
public FromStringWithRadixToNumberDeserializer(StdDeserializer<?> src, int radix) { | ||
super(src); | ||
this.radix = radix; | ||
} | ||
|
||
@Override | ||
public Number deserialize(JsonParser p, DeserializationContext ctxt) | ||
throws IOException { | ||
Class<?> handledType = handledType(); | ||
|
||
if (p.currentToken() != JsonToken.VALUE_STRING) { | ||
ctxt.reportInputMismatch(handledType, | ||
"Read something other than string when deserializing a value using FromStringWithRadixToNumberDeserializer."); | ||
} | ||
|
||
String text = p.getText(); | ||
|
||
if (handledType.equals(BigInteger.class)) { | ||
return new BigInteger(text, radix); | ||
} else if (handledType.equals(byte.class) || handledType.equals(Byte.class)) { | ||
return Byte.parseByte(text, radix); | ||
} else if (handledType.equals(short.class) || handledType.equals(Short.class)) { | ||
return Short.parseShort(text, radix); | ||
} else if (handledType.equals(int.class) || handledType.equals(Integer.class)) { | ||
return Integer.parseInt(text, radix); | ||
} else if (handledType.equals(long.class) || handledType.equals(Long.class)) { | ||
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 commentThe 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. |
||
return null;//should not reach here | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.