Skip to content

Commit

Permalink
Test demonstrating Issue jsog#15
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoft committed Apr 30, 2017
1 parent 01a0cd9 commit 675fa6d
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/test/java/com/voodoodyne/jackson/jsog/Issue15Test.java
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 {}
}
24 changes: 24 additions & 0 deletions src/test/java/com/voodoodyne/jackson/jsog/Thing.java
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;
}
}

0 comments on commit 675fa6d

Please sign in to comment.