You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import static org.junit.Assert.*;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.persistence.OneToMany;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
public class JacksonHibernateModuleTest {
private static final String EXPECTED_JSON = "{\"m\":{\"A\":\"A\"}}";
@Test
public void testMap() throws Exception {
Y object = new Y();
object.m.put("A", "A");
assertEquals(EXPECTED_JSON, mapWithoutHibernateModule(object));
assertEquals(EXPECTED_JSON, mapWithHibernateModule(object));
}
@Test
public void testMapWithOneToMany() throws Exception {
X object = new X();
object.m.put("A", "A");
assertEquals(EXPECTED_JSON, mapWithoutHibernateModule(object));
assertEquals(EXPECTED_JSON, mapWithHibernateModule(object));
}
private String mapWithHibernateModule(Object object) throws JsonProcessingException {
return new ObjectMapper().registerModule(new Hibernate4Module()).writeValueAsString(object);
}
private String mapWithoutHibernateModule(Object object) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(object);
}
private static final class X {
@OneToMany
public final Map<String, String> m = new LinkedHashMap<String, String>();
}
private static final class Y {
public final Map<String, String> m = new LinkedHashMap<String, String>();
}
}
(moved from https://jira.codehaus.org/browse/JACKSON-906 reported by Patrick Haas)
Serialization results in a NullPointerException when a Map field is annotated with @onetomany and the Hibernate4Module is loaded.
Tested with jackson-datatype-hibernate4-2.2.2.jar
The text was updated successfully, but these errors were encountered: