-
-
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.
Add an improved test for #735: turns out there is still at least one,…
… ordering-dependant issue
- Loading branch information
1 parent
503018b
commit de5642e
Showing
2 changed files
with
109 additions
and
45 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/test/java/com/fasterxml/jackson/databind/deser/TestCachingOfDeser.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,109 @@ | ||
package com.fasterxml.jackson.databind.deser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.BaseMapTest; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
@SuppressWarnings("serial") | ||
public class TestCachingOfDeser extends BaseMapTest | ||
{ | ||
// For [databind#735] | ||
public static class TestMapNoCustom { | ||
|
||
public Map<String, Integer> map; | ||
} | ||
|
||
public static class TestMapWithCustom { | ||
|
||
@JsonDeserialize(contentUsing = CustomDeserializer735.class) | ||
public Map<String, Integer> map; | ||
} | ||
|
||
public static class TestListWithCustom { | ||
@JsonDeserialize(contentUsing = CustomDeserializer735.class) | ||
public List<Integer> list; | ||
} | ||
|
||
public static class TestListNoCustom { | ||
public List<Integer> list; | ||
} | ||
|
||
public static class CustomDeserializer735 extends StdDeserializer<Integer> { | ||
public CustomDeserializer735() { | ||
super(Integer.class); | ||
} | ||
|
||
@Override | ||
public Integer deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
return 100 * p.getValueAsInt(); | ||
} | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* Unit tests | ||
/********************************************************** | ||
*/ | ||
|
||
final static String MAP_INPUT = "{\"map\":{\"a\":1}}"; | ||
final static String LIST_INPUT = "{\"list\":[1]}"; | ||
|
||
|
||
// Ok: first, use custom-annotated instance first, then standard | ||
public void testCustomMapCaching1() throws Exception | ||
{ | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
TestMapWithCustom mapC = mapper.readValue(MAP_INPUT, TestMapWithCustom.class); | ||
TestMapNoCustom mapStd = mapper.readValue(MAP_INPUT, TestMapNoCustom.class); | ||
|
||
assertNotNull(mapC.map); | ||
assertNotNull(mapStd.map); | ||
assertEquals(Integer.valueOf(100), mapC.map.get("a")); | ||
assertEquals(Integer.valueOf(1), mapStd.map.get("a")); | ||
} | ||
|
||
// And then standard first, custom next | ||
public void testCustomMapCaching2() throws Exception | ||
{ | ||
ObjectMapper mapper = new ObjectMapper(); | ||
TestMapNoCustom mapStd = mapper.readValue(MAP_INPUT, TestMapNoCustom.class); | ||
TestMapWithCustom mapC = mapper.readValue(MAP_INPUT, TestMapWithCustom.class); | ||
|
||
assertNotNull(mapStd.map); | ||
assertNotNull(mapC.map); | ||
assertEquals(Integer.valueOf(1), mapStd.map.get("a")); | ||
assertEquals(Integer.valueOf(100), mapC.map.get("a")); | ||
} | ||
|
||
// Ok: first, use custom-annotated instance first, then standard | ||
public void testCustomListCaching1() throws Exception { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
TestListWithCustom listC = mapper.readValue(LIST_INPUT, TestListWithCustom.class); | ||
TestListNoCustom listStd = mapper.readValue(LIST_INPUT, TestListNoCustom.class); | ||
|
||
assertNotNull(listC.list); | ||
assertNotNull(listStd.list); | ||
assertEquals(Integer.valueOf(100), listC.list.get(0)); | ||
assertEquals(Integer.valueOf(1), listStd.list.get(0)); | ||
} | ||
|
||
// First custom-annotated, then standard | ||
public void testCustomListCaching2() throws Exception { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
TestListNoCustom listStd = mapper.readValue(LIST_INPUT, TestListNoCustom.class); | ||
TestListWithCustom listC = mapper.readValue(LIST_INPUT, TestListWithCustom.class); | ||
|
||
assertNotNull(listC.list); | ||
assertNotNull(listStd.list); | ||
assertEquals(Integer.valueOf(100), listC.list.get(0)); | ||
assertEquals(Integer.valueOf(1), listStd.list.get(0)); | ||
} | ||
} |
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