-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3690: improve error message for to-string coercion
- Loading branch information
1 parent
a5b0af8
commit 2385416
Showing
9 changed files
with
85 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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
38 changes: 38 additions & 0 deletions
38
src/test/java/com/fasterxml/jackson/databind/convert/DisableCoercions3690Test.java
This file contains 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,38 @@ | ||
package com.fasterxml.jackson.databind.convert; | ||
|
||
import java.util.List; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.cfg.CoercionAction; | ||
import com.fasterxml.jackson.databind.cfg.CoercionInputShape; | ||
import com.fasterxml.jackson.databind.exc.InvalidFormatException; | ||
|
||
public class DisableCoercions3690Test extends BaseMapTest | ||
{ | ||
static class Input3690 { | ||
public List<String> field; | ||
} | ||
|
||
// [databind#3690] | ||
public void testFailMessage3690() throws Exception | ||
{ | ||
ObjectMapper mapper = jsonMapperBuilder() | ||
.withCoercionConfigDefaults(config -> { | ||
config.setCoercion(CoercionInputShape.Boolean, CoercionAction.Fail) | ||
.setCoercion(CoercionInputShape.Integer, CoercionAction.Fail) | ||
.setCoercion(CoercionInputShape.Float, CoercionAction.Fail) | ||
.setCoercion(CoercionInputShape.String, CoercionAction.Fail) | ||
.setCoercion(CoercionInputShape.Array, CoercionAction.Fail) | ||
.setCoercion(CoercionInputShape.Object, CoercionAction.Fail); | ||
}) | ||
.build(); | ||
String json = "{ \"field\": [ 1 ] }"; | ||
try { | ||
mapper.readValue(json, Input3690.class); | ||
fail("Should not pass"); | ||
} catch (InvalidFormatException e) { | ||
verifyException(e, "Cannot coerce Integer value (1)"); | ||
verifyException(e, "to `java.lang.String` value"); | ||
} | ||
} | ||
} |