-
-
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.
Merge pull request #801 from Kamil-Benedykcinski/2.5
Using JsonCreator cause generating invalid path reference in JsonMappingException
- Loading branch information
Showing
3 changed files
with
158 additions
and
14 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
62 changes: 62 additions & 0 deletions
62
...com/fasterxml/jackson/databind/deser/TestExceptionHandlingWithDefaultDeserialization.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,62 @@ | ||
package com.fasterxml.jackson.databind.deser; | ||
|
||
import com.fasterxml.jackson.databind.BaseMapTest; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
|
||
public class TestExceptionHandlingWithDefaultDeserialization extends BaseMapTest { | ||
|
||
static class Foo { | ||
|
||
private Bar bar; | ||
|
||
public Foo() { | ||
} | ||
|
||
public Bar getBar() { | ||
return bar; | ||
} | ||
} | ||
|
||
static class Bar { | ||
|
||
private Baz baz; | ||
|
||
public Bar() { | ||
} | ||
|
||
public Baz getBaz() { | ||
return baz; | ||
} | ||
} | ||
|
||
static class Baz { | ||
|
||
private String qux; | ||
|
||
public Baz() { | ||
} | ||
|
||
public String getQux() { | ||
return qux; | ||
} | ||
} | ||
|
||
public void testShouldThrowJsonMappingExceptionWithPathReference() throws IOException { | ||
// given | ||
ObjectMapper mapper = new ObjectMapper(); | ||
String input = "{\"bar\":{\"baz\":{qux:\"quxValue\"))}"; | ||
|
||
// when | ||
try { | ||
mapper.readValue(input, Foo.class); | ||
fail("Upsss! Exception has not been thrown."); | ||
} catch (JsonMappingException ex) { | ||
// then | ||
assertEquals("com.fasterxml.jackson.databind.deser.Foo[\"bar\"]->com.fasterxml.jackson.databind.deser.Bar[\"baz\"]", | ||
ex.getPathReference()); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...fasterxml/jackson/databind/deser/TestExceptionHandlingWithJsonCreatorDeserialization.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,70 @@ | ||
package com.fasterxml.jackson.databind.deser; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.BaseMapTest; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.io.IOException; | ||
|
||
public class TestExceptionHandlingWithJsonCreatorDeserialization extends BaseMapTest { | ||
|
||
static class Foo { | ||
|
||
private Bar bar; | ||
|
||
@JsonCreator | ||
public Foo(@JsonProperty("bar") Bar bar) { | ||
this.bar = bar; | ||
} | ||
|
||
public Bar getBar() { | ||
return bar; | ||
} | ||
} | ||
|
||
static class Bar { | ||
|
||
private Baz baz; | ||
|
||
@JsonCreator | ||
public Bar(@JsonProperty("baz") Baz baz) { | ||
this.baz = baz; | ||
} | ||
|
||
public Baz getBaz() { | ||
return baz; | ||
} | ||
} | ||
|
||
static class Baz { | ||
|
||
private String qux; | ||
|
||
@JsonCreator | ||
public Baz(@JsonProperty("qux") String qux) { | ||
this.qux = qux; | ||
} | ||
|
||
public String getQux() { | ||
return qux; | ||
} | ||
} | ||
|
||
public void testShouldThrowJsonMappingExceptionWithPathReference() throws IOException { | ||
// given | ||
ObjectMapper mapper = new ObjectMapper(); | ||
String input = "{\"bar\":{\"baz\":{qux:\"quxValue\"))}"; | ||
|
||
// when | ||
try { | ||
mapper.readValue(input, Foo.class); | ||
fail("Upsss! Exception has not been thrown."); | ||
} catch (JsonMappingException ex) { | ||
// then | ||
assertEquals("com.fasterxml.jackson.databind.deser.Foo[\"bar\"]->com.fasterxml.jackson.databind.deser.Bar[\"baz\"]", | ||
ex.getPathReference()); | ||
} | ||
} | ||
} |