aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml
diff options
context:
space:
mode:
authorTatu Saloranta <tatu.saloranta@iki.fi>2020-06-29 22:21:40 -0700
committerTatu Saloranta <tatu.saloranta@iki.fi>2020-06-29 22:21:40 -0700
commita4420cdc5af51c876ba59660115593afff49ad92 (patch)
tree693ce830d0a43471de542f1782dc99c97cf35fae /src/main/java/com/fasterxml
parent40701f15a81c1f2ed7aae2a43173f97ab7403af9 (diff)
downloadjackson-databind-a4420cdc5af51c876ba59660115593afff49ad92.tar.gz
Add support for some more coercions for Delegating creators (Int/Long from String)
Diffstat (limited to 'src/main/java/com/fasterxml')
-rw-r--r--src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java
index 7c77fc057..2be2beee6 100644
--- a/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java
+++ b/src/main/java/com/fasterxml/jackson/databind/deser/std/StdDeserializer.java
@@ -281,16 +281,30 @@ public abstract class StdDeserializer<T>
// 28-Sep-2011, tatu: Ok this is not clean at all; but since there are legacy
// systems that expect conversions in some cases, let's just add a minimal
// patch (note: same could conceivably be used for numbers too).
- if ((inst != null) && inst.canCreateFromBoolean()) {
- // 29-May-2020, tatu: With 2.12 can and should use CoercionConfig so:
- if (ctxt.findCoercionAction(LogicalType.Boolean, Boolean.class,
- CoercionInputShape.String) == CoercionAction.TryConvert) {
- String str = value.trim();
- if ("true".equals(str)) {
- return (T) inst.createFromBoolean(ctxt, true);
+ if (inst != null) {
+ if (inst.canCreateFromInt()) {
+ if (ctxt.findCoercionAction(LogicalType.Integer, Integer.class,
+ CoercionInputShape.String) == CoercionAction.TryConvert) {
+ return (T) inst.createFromInt(ctxt, _parseIntPrimitive(ctxt, value));
}
- if ("false".equals(str)) {
- return (T) inst.createFromBoolean(ctxt, false);
+ }
+ if (inst.canCreateFromLong()) {
+ if (ctxt.findCoercionAction(LogicalType.Integer, Long.class,
+ CoercionInputShape.String) == CoercionAction.TryConvert) {
+ return (T) inst.createFromLong(ctxt, _parseLongPrimitive(ctxt, value));
+ }
+ }
+ if (inst.canCreateFromBoolean()) {
+ // 29-May-2020, tatu: With 2.12 can and should use CoercionConfig so:
+ if (ctxt.findCoercionAction(LogicalType.Boolean, Boolean.class,
+ CoercionInputShape.String) == CoercionAction.TryConvert) {
+ String str = value.trim();
+ if ("true".equals(str)) {
+ return (T) inst.createFromBoolean(ctxt, true);
+ }
+ if ("false".equals(str)) {
+ return (T) inst.createFromBoolean(ctxt, false);
+ }
}
}
}