From c37e0ff21b5e7a278eec11303af7e76c7ed240fc Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 18 Oct 2013 10:18:07 -0700 Subject: [PATCH] Fix #36 for 2.2.4 (assuming it completely resolves the prob) --- .../hibernate3/PersistentCollectionSerializer.java | 5 +++++ .../hibernate4/PersistentCollectionSerializer.java | 12 ++++++------ release-notes/VERSION | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hibernate3/src/main/java/com/fasterxml/jackson/datatype/hibernate3/PersistentCollectionSerializer.java b/hibernate3/src/main/java/com/fasterxml/jackson/datatype/hibernate3/PersistentCollectionSerializer.java index 6df3ca48..d8394a67 100644 --- a/hibernate3/src/main/java/com/fasterxml/jackson/datatype/hibernate3/PersistentCollectionSerializer.java +++ b/hibernate3/src/main/java/com/fasterxml/jackson/datatype/hibernate3/PersistentCollectionSerializer.java @@ -135,6 +135,11 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid protected boolean usesLazyLoading(BeanProperty property) { if (property != null) { + // As per [Issue#36] + ElementCollection ec = property.getAnnotation(ElementCollection.class); + if (ec != null) { + return (ec.fetch() == FetchType.LAZY); + } OneToMany ann1 = property.getAnnotation(OneToMany.class); if (ann1 != null) { return (ann1.fetch() == FetchType.LAZY); diff --git a/hibernate4/src/main/java/com/fasterxml/jackson/datatype/hibernate4/PersistentCollectionSerializer.java b/hibernate4/src/main/java/com/fasterxml/jackson/datatype/hibernate4/PersistentCollectionSerializer.java index 40c4ea7e..0f142fbf 100644 --- a/hibernate4/src/main/java/com/fasterxml/jackson/datatype/hibernate4/PersistentCollectionSerializer.java +++ b/hibernate4/src/main/java/com/fasterxml/jackson/datatype/hibernate4/PersistentCollectionSerializer.java @@ -2,15 +2,10 @@ import java.io.IOException; -import javax.persistence.FetchType; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.OneToOne; +import javax.persistence.*; import org.hibernate.collection.spi.PersistentCollection; - import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; @@ -141,6 +136,11 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid protected boolean usesLazyLoading(BeanProperty property) { if (property != null) { + // As per [Issue#36] + ElementCollection ec = property.getAnnotation(ElementCollection.class); + if (ec != null) { + return (ec.fetch() == FetchType.LAZY); + } OneToMany ann1 = property.getAnnotation(OneToMany.class); if (ann1 != null) { return (ann1.fetch() == FetchType.LAZY); diff --git a/release-notes/VERSION b/release-notes/VERSION index cd42e616..5a40421f 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -3,6 +3,7 @@ Jackson module to support datatypes of Hibernate 3.6 / 4.x, based on Jackson 2.x Version: 2.2.4 (xx-xxx-2013) +#36: Support `@ElementCollection` for specifying lazy-loading #44: NullPointerException when @OneToMany map is encountered (reported by Patrick H)