-
-
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.
- Loading branch information
1 parent
f92a6b3
commit e412926
Showing
2 changed files
with
112 additions
and
1 deletion.
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
83 changes: 83 additions & 0 deletions
83
src/test/java/com/fasterxml/jackson/failing/ConvertingAbstractSerializer795Test.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,83 @@ | ||
package com.fasterxml.jackson.failing; | ||
|
||
import com.fasterxml.jackson.annotation.*; | ||
import com.fasterxml.jackson.databind.*; | ||
import com.fasterxml.jackson.databind.annotation.*; | ||
import com.fasterxml.jackson.databind.util.StdConverter; | ||
|
||
// for [databind#795] | ||
public class ConvertingAbstractSerializer795Test extends BaseMapTest | ||
{ | ||
public static abstract class AbstractCustomType { | ||
final String value; | ||
public AbstractCustomType(String v) { | ||
this.value = v; | ||
} | ||
} | ||
|
||
public static class ConcreteCustomType extends AbstractCustomType { | ||
public ConcreteCustomType(String v) { | ||
super(v); | ||
} | ||
} | ||
|
||
public static class AbstractCustomTypeDeserializationConverter extends StdConverter<String, AbstractCustomType>{ | ||
|
||
@Override | ||
public AbstractCustomType convert(String arg) { | ||
return new ConcreteCustomType(arg); | ||
} | ||
} | ||
|
||
public static class AbstractCustomTypeUser { | ||
@JsonProperty | ||
@JsonDeserialize(converter = AbstractCustomTypeDeserializationConverter.class) | ||
private final AbstractCustomType customField; | ||
|
||
@JsonCreator AbstractCustomTypeUser(@JsonProperty("customField") | ||
AbstractCustomType customField) { | ||
this.customField = customField; | ||
} | ||
} | ||
|
||
public static class NonAbstractCustomType { | ||
final String value; | ||
public NonAbstractCustomType(String v) { | ||
this.value = v; | ||
} | ||
} | ||
|
||
|
||
public static class NonAbstractCustomTypeDeserializationConverter extends StdConverter<String, NonAbstractCustomType>{ | ||
|
||
@Override | ||
public NonAbstractCustomType convert(String arg) { | ||
return new NonAbstractCustomType(arg); | ||
} | ||
} | ||
|
||
|
||
public static class NonAbstractCustomTypeUser { | ||
@JsonProperty | ||
@JsonDeserialize(converter = NonAbstractCustomTypeDeserializationConverter.class) | ||
private final NonAbstractCustomType customField; | ||
|
||
@JsonCreator NonAbstractCustomTypeUser(@JsonProperty("customField") NonAbstractCustomType customField) { | ||
this.customField = customField; | ||
} | ||
} | ||
|
||
private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); | ||
|
||
public void testAbstractTypeDeserialization() throws Exception { | ||
String test="{\"customField\": \"customString\"}"; | ||
AbstractCustomTypeUser cu = JSON_MAPPER.readValue(test, AbstractCustomTypeUser.class); | ||
assertNotNull(cu); | ||
} | ||
|
||
public void testNonAbstractDeserialization() throws Exception { | ||
String test="{\"customField\": \"customString\"}"; | ||
NonAbstractCustomTypeUser cu = JSON_MAPPER.readValue(test, NonAbstractCustomTypeUser.class); | ||
assertNotNull(cu); | ||
} | ||
} |