Permalink
Browse files

Update module to 2.0.0, naming, type

  • Loading branch information...
1 parent 8c9cd8b commit 5f7f07864873d2459dfdf27dc16b6164710e1621 Tatu committed Feb 1, 2012
Showing with 184 additions and 108 deletions.
  1. +21 −0 .gitignore
  2. +14 −2 pom.xml
  3. +12 −6 ...ain/java/com/fasterxml/jackson/{module → datatype}/hibernate/HibernateAnnotationIntrospector.java
  4. +6 −10 src/main/java/com/fasterxml/jackson/{module → datatype}/hibernate/HibernateModule.java
  5. +8 −10 src/main/java/com/fasterxml/jackson/{module → datatype}/hibernate/HibernateProxySerializer.java
  6. +14 −16 src/main/java/com/fasterxml/jackson/{module → datatype}/hibernate/HibernateSerializers.java
  7. +12 −0 src/main/java/com/fasterxml/jackson/datatype/hibernate/ModuleVersion.java
  8. +20 −27 ...main/java/com/fasterxml/jackson/{module → datatype}/hibernate/PersistentCollectionSerializer.java
  9. +3 −0 src/main/resources/com/fasterxml/jackson/datatype/hibernate/VERSION.txt
  10. +3 −2 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/BaseTest.java
  11. +8 −4 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/HibernateTest.java
  12. +42 −0 src/test/java/com/fasterxml/jackson/datatype/hibernate/TestVersions.java
  13. +2 −2 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/Customer.java
  14. +3 −13 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/Employee.java
  15. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/Office.java
  16. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/Order.java
  17. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/OrderDetail.java
  18. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/OrderDetailId.java
  19. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/Payment.java
  20. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/PaymentId.java
  21. +1 −1 src/test/java/com/fasterxml/jackson/{module → datatype}/hibernate/data/Product.java
  22. +9 −9 src/test/resources/META-INF/persistence.xml
View
@@ -0,0 +1,21 @@
+# use glob syntax.
+syntax: glob
+*.class
+*~
+*.bak
+*.off
+*.old
+.DS_Store
+
+# building
+target
+
+# Eclipse
+.classpath
+.project
+.settings
+
+# IDEA
+*.iml
+*.ipr
+*.iws
View
16 pom.xml
@@ -56,12 +56,12 @@ Hibernate (http://hibernate.org) data types.
<dependencies>
<!-- Extends Jackson; supports Hibernate datatypes, so: -->
<dependency>
- <groupId>org.codehaus.jackson</groupId>
+ <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.codehaus.jackson</groupId>
+ <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
@@ -87,6 +87,12 @@ Hibernate (http://hibernate.org) data types.
<version>4.8.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
@@ -108,6 +114,12 @@ Hibernate (http://hibernate.org) data types.
</dependencies>
<build>
+ <resources>
+ <resource> <!-- Needed to add version info -->
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -1,19 +1,20 @@
-package com.fasterxml.jackson.module.hibernate;
+package com.fasterxml.jackson.datatype.hibernate;
import java.lang.annotation.Annotation;
+
import javax.persistence.Transient;
-import org.codehaus.jackson.map.introspect.AnnotatedConstructor;
-import org.codehaus.jackson.map.introspect.AnnotatedField;
-import org.codehaus.jackson.map.introspect.AnnotatedMethod;
-import org.codehaus.jackson.map.introspect.NopAnnotationIntrospector;
+import com.fasterxml.jackson.core.Version;
+
+import com.fasterxml.jackson.databind.AnnotationIntrospector;
+import com.fasterxml.jackson.databind.introspect.*;
/**
* Simple {@link org.codehaus.jackson.map.AnnotationIntrospector} that adds support for using
* {@link Transient} to denote ignorable fields (alongside with Jackson
* and/or JAXB annotations).
*/
-public class HibernateAnnotationIntrospector extends NopAnnotationIntrospector
+public class HibernateAnnotationIntrospector extends AnnotationIntrospector
{
/**
* Whether we should check for existence of @Transient or not.
@@ -38,6 +39,11 @@ public HibernateAnnotationIntrospector setUseTransient(boolean state) {
_cfgCheckTransient = state;
return this;
}
+
+ @Override
+ public Version version() {
+ return ModuleVersion.instance.version();
+ }
/*
/**********************************************************************
@@ -1,15 +1,11 @@
-package com.fasterxml.jackson.module.hibernate;
+package com.fasterxml.jackson.datatype.hibernate;
-import org.codehaus.jackson.Version;
-import org.codehaus.jackson.map.*;
+import com.fasterxml.jackson.core.Version;
+
+import com.fasterxml.jackson.databind.*;
public class HibernateModule extends Module
{
- private final String NAME = "HibernateModule";
-
- // Should externalize this somehow
- private final static Version VERSION = new Version(0, 1, 0, null); // 0.1.0
-
/**
* Enumeration that defines all togglable features this module
*/
@@ -78,8 +74,8 @@ private Feature(boolean defaultState) {
public HibernateModule() { }
- @Override public String getModuleName() { return NAME; }
- @Override public Version version() { return VERSION; }
+ @Override public String getModuleName() { return "jackson-datatype-hibernate"; }
+ @Override public Version version() { return ModuleVersion.instance.version(); }
@Override
public void setupModule(SetupContext context)
@@ -1,17 +1,15 @@
-package com.fasterxml.jackson.module.hibernate;
+package com.fasterxml.jackson.datatype.hibernate;
import java.io.IOException;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.map.BeanProperty;
-import org.codehaus.jackson.map.JsonSerializer;
-import org.codehaus.jackson.map.SerializerProvider;
-import org.codehaus.jackson.map.TypeSerializer;
-import org.codehaus.jackson.map.ser.impl.PropertySerializerMap;
+import com.fasterxml.jackson.core.*;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
+import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
/**
* Serializer to use for values proxied using {@link HibernateProxy}.
@@ -44,11 +42,11 @@
/**********************************************************************
*/
- public HibernateProxySerializer(BeanProperty property, boolean forceLazyLoading)
+ public HibernateProxySerializer(boolean forceLazyLoading)
{
- _property = property;
_forceLazyLoading = forceLazyLoading;
_dynamicSerializers = PropertySerializerMap.emptyMap();
+ _property = null;
}
/*
@@ -1,20 +1,19 @@
-package com.fasterxml.jackson.module.hibernate;
+package com.fasterxml.jackson.datatype.hibernate;
import java.util.*;
import org.hibernate.collection.PersistentCollection;
import org.hibernate.collection.PersistentMap;
import org.hibernate.proxy.HibernateProxy;
-import org.codehaus.jackson.map.*;
-import org.codehaus.jackson.map.type.CollectionType;
-import org.codehaus.jackson.map.type.MapType;
-import org.codehaus.jackson.map.type.TypeFactory;
-import org.codehaus.jackson.type.JavaType;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
+import com.fasterxml.jackson.databind.ser.*;
+import com.fasterxml.jackson.databind.type.*;
+import com.fasterxml.jackson.datatype.hibernate.HibernateModule.Feature;
-import com.fasterxml.jackson.module.hibernate.HibernateModule.Feature;
-public class HibernateSerializers extends Serializers.None
+public class HibernateSerializers extends Serializers.Base
{
protected final int _moduleFeatures;
@@ -24,9 +23,8 @@ public HibernateSerializers(int features)
}
@Override
- public JsonSerializer<?> findSerializer(
- SerializationConfig config, JavaType type,
- BeanDescription beanDesc, BeanProperty beanProperty )
+ public JsonSerializer<?> findSerializer(SerializationConfig config,
+ JavaType type, BeanDescription beanDesc)
{
Class<?> raw = type.getRawClass();
@@ -38,14 +36,14 @@ public HibernateSerializers(int features)
}
if (HibernateProxy.class.isAssignableFrom(raw)) {
- return new HibernateProxySerializer(beanProperty, isEnabled(Feature.FORCE_LAZY_LOADING));
+ return new HibernateProxySerializer(isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
}
@Override
public JsonSerializer<?> findCollectionSerializer(SerializationConfig config,
- CollectionType type, BeanDescription beanDesc, BeanProperty property,
+ CollectionType type, BeanDescription beanDesc,
TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
{
Class<?> raw = type.getRawClass();
@@ -54,21 +52,21 @@ public HibernateSerializers(int features)
/* And for those, figure out "fallback type"; we MUST have some idea of
* type to deserialize, aside from nominal PersistentXxx type.
*/
- return new PersistentCollectionSerializer(property, _figureFallbackType(config, type),
+ return new PersistentCollectionSerializer(_figureFallbackType(config, type),
isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
}
@Override
public JsonSerializer<?> findMapSerializer(SerializationConfig config,
- MapType type, BeanDescription beanDesc, BeanProperty property,
+ MapType type, BeanDescription beanDesc,
JsonSerializer<Object> keySerializer,
TypeSerializer elementTypeSerializer, JsonSerializer<Object> elementValueSerializer)
{
Class<?> raw = type.getRawClass();
if (PersistentMap.class.isAssignableFrom(raw)) {
- return new PersistentCollectionSerializer(property, _figureFallbackType(config, type),
+ return new PersistentCollectionSerializer(_figureFallbackType(config, type),
isEnabled(Feature.FORCE_LAZY_LOADING));
}
return null;
@@ -0,0 +1,12 @@
+package com.fasterxml.jackson.datatype.hibernate;
+
+import com.fasterxml.jackson.core.util.VersionUtil;
+
+/**
+ * Helper class used for finding and caching version information
+ * for this module.
+ */
+class ModuleVersion extends VersionUtil
+{
+ public final static ModuleVersion instance = new ModuleVersion();
+}
@@ -1,28 +1,23 @@
-package com.fasterxml.jackson.module.hibernate;
+package com.fasterxml.jackson.datatype.hibernate;
import java.io.IOException;
import org.hibernate.collection.PersistentCollection;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.map.*;
-import org.codehaus.jackson.type.JavaType;
+import com.fasterxml.jackson.core.*;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
+import com.fasterxml.jackson.databind.ser.*;
/**
* Wrapper serializer used to handle aspects of lazy loading that can be used
* for Hibernate collection datatypes.
*/
public class PersistentCollectionSerializer
extends JsonSerializer<PersistentCollection>
- implements ContextualSerializer<PersistentCollection>,
- ResolvableSerializer
+ implements ContextualSerializer
{
- /**
- * Property that has collection value to handle
- */
- protected final BeanProperty _property;
-
protected final boolean _forceLazyLoading;
/**
@@ -34,28 +29,33 @@
/**
* Serializer to which we delegate if serialization is not blocked.
*/
- protected JsonSerializer<Object> _serializer;
+ protected final JsonSerializer<Object> _serializer;
/*
/**********************************************************************
/* Life cycle
/**********************************************************************
*/
- public PersistentCollectionSerializer(BeanProperty property, JavaType type,
- boolean forceLazyLoading)
+ public PersistentCollectionSerializer(JavaType type, boolean forceLazyLoading) {
+ this(type, forceLazyLoading, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ public PersistentCollectionSerializer(JavaType type, boolean forceLazyLoading,
+ JsonSerializer<?> serializer)
{
- _property = property;
_serializationType = type;
_forceLazyLoading = forceLazyLoading;
+ _serializer = (JsonSerializer<Object>) serializer;
}
/**
* We need to resolve actual serializer once we know the context; specifically
* must know type of property being serialized.
* If not known
*/
- public JsonSerializer<PersistentCollection> createContextual(SerializationConfig config,
+ public JsonSerializer<PersistentCollection> createContextual(SerializerProvider provider,
BeanProperty property)
throws JsonMappingException
{
@@ -65,16 +65,9 @@ public PersistentCollectionSerializer(BeanProperty property, JavaType type,
* 'property' refers to field/method and main type, but contents of
* that type may also be resolved... in which case this would fail.
*/
- if (property != null) {
- return new PersistentCollectionSerializer(property, property.getType(),
- _forceLazyLoading);
- }
- return this;
- }
-
- public void resolve(SerializerProvider provider) throws JsonMappingException
- {
- _serializer = provider.findValueSerializer(_serializationType, _property);
+ JsonSerializer<?> ser = provider.findValueSerializer(_serializationType, property);
+ return new PersistentCollectionSerializer(property.getType(),
+ _forceLazyLoading, ser);
}
/*
@@ -0,0 +1,3 @@
+${project.version}
+${project.groupId}
+${project.artifactId}
@@ -1,8 +1,9 @@
-package com.fasterxml.jackson.module.hibernate;
+package com.fasterxml.jackson.datatype.hibernate;
import java.util.Arrays;
-import org.codehaus.jackson.map.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.hibernate.HibernateModule;
public abstract class BaseTest extends junit.framework.TestCase
{
Oops, something went wrong.

0 comments on commit 5f7f078

Please sign in to comment.