forked from jsog/jsog-jackson
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/test/java/com/voodoodyne/jackson/jsog/Issue15Test.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.voodoodyne.jackson.jsog; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIdentityInfo; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
import java.io.IOException; | ||
import java.util.Date; | ||
|
||
/** | ||
* Demonstrates the inability to round trip serialize deserialize when using DefaultTyping.NON_FINAL, | ||
* and version fixes for NON_CONCRETE strategies. | ||
*/ | ||
public class Issue15Test { | ||
|
||
@Test // always works | ||
public void testIssue5WorkaroundObject() throws IOException { | ||
testWithPolymorphicStrategy(ObjectMapper.DefaultTyping.JAVA_LANG_OBJECT); | ||
|
||
} | ||
@Test(enabled = false) // works with Jackson 2.5.4+ | ||
public void testIssue5WorkaroundObjectAndNonConcrete() throws IOException { | ||
testWithPolymorphicStrategy(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE); | ||
|
||
} | ||
@Test(enabled = false) // works with Jackson 2.5.4+ | ||
public void testIssue5WorkaroundNonConcreteAndArrays() throws IOException { | ||
testWithPolymorphicStrategy(ObjectMapper.DefaultTyping.NON_CONCRETE_AND_ARRAYS); | ||
|
||
} | ||
@Test(enabled = false) // fails on Jackson 2.8.8 (no working version as of this date) | ||
public void testIssue5WorkaroundNonFinal() throws IOException { | ||
testWithPolymorphicStrategy(ObjectMapper.DefaultTyping.NON_FINAL); | ||
} | ||
|
||
private void testWithPolymorphicStrategy(ObjectMapper.DefaultTyping typingStragegy) throws IOException { | ||
Thing t = new Thing(); | ||
t.setName("foo"); | ||
|
||
t.setDate(new Date()); | ||
|
||
ObjectMapper mapper = new ObjectMapper(); | ||
mapper.enableDefaultTyping(typingStragegy); | ||
|
||
// issue is JSOG specific since removing this line causes all tests to | ||
// pass in 2.5.4 (did not test earlier) | ||
mapper.addMixIn(Object.class, JSOGMixin.class); | ||
|
||
// No difference if we use the module workaround from Issue #5 | ||
|
||
// SimpleModule jModule = new SimpleModule(); | ||
// jModule.setMixInAnnotation(Object.class, JSOGMixin.class); | ||
// mapper.registerModule(jModule); | ||
|
||
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(t); | ||
mapper.readValue(json, Thing.class); | ||
} | ||
|
||
@JsonIdentityInfo(generator = JSOGGenerator.class) private static class JSOGMixin {} | ||
} |
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,24 @@ | ||
package com.voodoodyne.jackson.jsog; | ||
|
||
import java.util.Date; | ||
|
||
public class Thing { | ||
private String name; | ||
private Date date; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(Date date) { | ||
this.date = date; | ||
} | ||
} |