Permalink
Browse files

Upgraded to jackson 2 snapshot

  • Loading branch information...
1 parent 8a6fbee commit a6c0bf588f99d35bf4f920974254396f92099ab0 @jroper jroper committed Dec 25, 2011
Showing with 297 additions and 107 deletions.
  1. +4 −3 buildfile
  2. +16 −19 src/main/java/de/undercouch/bson4jackson/BsonFactory.java
  3. +8 −8 src/main/java/de/undercouch/bson4jackson/BsonGenerator.java
  4. +17 −22 src/main/java/de/undercouch/bson4jackson/BsonModule.java
  5. +27 −14 src/main/java/de/undercouch/bson4jackson/BsonParser.java
  6. +1 −1 src/main/java/de/undercouch/bson4jackson/io/StaticBuffers.java
  7. +1 −1 src/main/java/de/undercouch/bson4jackson/serializers/BsonCalendarSerializer.java
  8. +1 −1 src/main/java/de/undercouch/bson4jackson/serializers/BsonDateSerializer.java
  9. +1 −2 src/main/java/de/undercouch/bson4jackson/serializers/BsonJavascriptSerializer.java
  10. +1 −1 src/main/java/de/undercouch/bson4jackson/serializers/BsonObjectIdSerializer.java
  11. +1 −1 src/main/java/de/undercouch/bson4jackson/serializers/BsonRegexSerializer.java
  12. +5 −5 src/main/java/de/undercouch/bson4jackson/serializers/BsonSerializer.java
  13. +31 −0 src/main/java/de/undercouch/bson4jackson/serializers/BsonSerializers.java
  14. +1 −2 src/main/java/de/undercouch/bson4jackson/serializers/BsonSymbolSerializer.java
  15. +1 −2 src/main/java/de/undercouch/bson4jackson/serializers/BsonTimestampSerializer.java
  16. +1 −5 src/main/java/de/undercouch/bson4jackson/serializers/BsonUuidSerializer.java
  17. +153 −0 src/main/java/de/undercouch/bson4jackson/serializers/SimpleSerializers.java
  18. +19 −12 src/main/java/de/undercouch/bson4jackson/uuid/BsonUuidModule.java
  19. +2 −2 src/test/java/de/undercouch/bson4jackson/BsonGeneratorTest.java
  20. +6 −6 src/test/java/de/undercouch/bson4jackson/BsonParserTest.java
View
7 buildfile
@@ -3,15 +3,16 @@ require "buildr/bnd"
repositories.remote << 'http://repo1.maven.org/maven2'
repositories.remote << Buildr::Bnd.remote_repository
-JACKSON = 'org.codehaus.jackson:jackson-core-asl:jar:1.7.4'
-JACKSON_MAPPER = 'org.codehaus.jackson:jackson-mapper-asl:jar:1.7.4'
+JACKSON = 'com.fasterxml.jackson.core:jackson-core:jar:2.0.0-SNAPSHOT'
+JACKSON_ANNOTATIONS = 'com.fasterxml.jackson.core:jackson-annotations:jar:2.0.0-SNAPSHOT'
+JACKSON_DATABIND = 'com.fasterxml.jackson.core:jackson-databind:jar:2.0.0-SNAPSHOT'
MONGODB = 'org.mongodb:mongo-java-driver:jar:2.5.3'
define 'bson4jackson' do
project.version = '1.2.0'
project.group = 'de.undercouch'
- compile.with JACKSON, JACKSON_MAPPER
+ compile.with JACKSON, JACKSON_ANNOTATIONS, JACKSON_DATABIND
test.with MONGODB
package(:bundle).tap do |bnd|
View
35 src/main/java/de/undercouch/bson4jackson/BsonFactory.java
@@ -14,21 +14,16 @@
package de.undercouch.bson4jackson;
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.core.io.IOContext;
+
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-import org.codehaus.jackson.JsonEncoding;
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.ObjectCodec;
-import org.codehaus.jackson.io.IOContext;
-
/**
* Factory for {@link BsonGenerator} and {@link BsonParser}
* @author Michel Kraemer
@@ -164,22 +159,24 @@ public BsonGenerator createJsonGenerator(OutputStream out) throws IOException {
}
return g;
}
-
+
+
+
@Override
public BsonParser createJsonParser(InputStream in) throws IOException {
- BsonParser p = new BsonParser(_parserFeatures, _bsonParserFeatures, in);
- ObjectCodec codec = getCodec();
- if (codec != null) {
- p.setCodec(codec);
- }
- return p;
+ return _createJsonParser(in, _createContext(in, false));
}
-
+
@Override
- protected JsonParser _createJsonParser(InputStream in, IOContext ctxt)
+ protected BsonParser _createJsonParser(InputStream in, IOContext ctxt)
throws IOException, JsonParseException {
- return createJsonParser(in);
- }
+ BsonParser p = new BsonParser(ctxt, _parserFeatures, _bsonParserFeatures, in);
+ ObjectCodec codec = getCodec();
+ if (codec != null) {
+ p.setCodec(codec);
+ }
+ return p;
+ }
@Override
protected JsonParser _createJsonParser(Reader r, IOContext ctxt)
View
16 src/main/java/de/undercouch/bson4jackson/BsonGenerator.java
@@ -26,25 +26,25 @@
import java.util.Map;
import java.util.regex.Pattern;
+import com.fasterxml.jackson.core.Base64Variant;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.base.GeneratorBase;
+import com.fasterxml.jackson.core.json.JsonWriteContext;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.io.ByteOrderUtil;
import de.undercouch.bson4jackson.types.JavaScript;
import de.undercouch.bson4jackson.types.ObjectId;
import de.undercouch.bson4jackson.types.Symbol;
import de.undercouch.bson4jackson.types.Timestamp;
-import org.codehaus.jackson.Base64Variant;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.impl.JsonGeneratorBase;
-import org.codehaus.jackson.impl.JsonWriteContext;
import de.undercouch.bson4jackson.io.DynamicOutputBuffer;
-import org.codehaus.jackson.map.SerializerProvider;
/**
* Writes BSON code to the provided output stream
* @author Michel Kraemer
*/
-public class BsonGenerator extends JsonGeneratorBase {
+public class BsonGenerator extends GeneratorBase {
/**
* Defines toggable features
*/
@@ -138,7 +138,7 @@ public DocumentInfo(int headerPos, boolean array) {
/**
* Creates a new generator
* @param jsonFeatures bit flag composed of bits that indicate which
- * {@link org.codehaus.jackson.JsonGenerator.Feature}s are enabled.
+ * {@link com.fasterxml.jackson.core.JsonGenerator.Feature}s are enabled.
* @param bsonFeatures bit flag composed of bits that indicate which
* {@link Feature}s are enabled.
* @param out the output stream to write to
View
39 src/main/java/de/undercouch/bson4jackson/BsonModule.java
@@ -14,35 +14,30 @@
package de.undercouch.bson4jackson;
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.Module;
import de.undercouch.bson4jackson.serializers.*;
-import de.undercouch.bson4jackson.types.JavaScript;
-import de.undercouch.bson4jackson.types.ObjectId;
-import de.undercouch.bson4jackson.types.Symbol;
-import de.undercouch.bson4jackson.types.Timestamp;
-import org.codehaus.jackson.Version;
-import org.codehaus.jackson.map.module.SimpleModule;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.UUID;
-import java.util.regex.Pattern;
/**
* Module that configures Jackson to be able to correctly handle all BSON types
*
* @author James Roper
* @since 1.3
*/
-public class BsonModule extends SimpleModule {
- public BsonModule() {
- super("BsonModule", new Version(1, 3, 0, ""));
- addSerializer(UUID.class, new BsonUuidSerializer());
- addSerializer(Date.class, new BsonDateSerializer());
- addSerializer(Calendar.class, new BsonCalendarSerializer());
- addSerializer(ObjectId.class, new BsonObjectIdSerializer());
- addSerializer(Pattern.class, new BsonRegexSerializer());
- addSerializer(JavaScript.class, new BsonJavaScriptSerializer());
- addSerializer(Timestamp.class, new BsonTimestampSerializer());
- addSerializer(Symbol.class, new BsonSymbolSerializer());
+public class BsonModule extends Module {
+
+ @Override
+ public String getModuleName() {
+ return "BsonModule";
+ }
+
+ @Override
+ public Version version() {
+ return new Version(2, 0, 0, "");
+ }
+
+ @Override
+ public void setupModule(SetupContext context) {
+ context.addSerializers(new BsonSerializers());
}
}
View
41 src/main/java/de/undercouch/bson4jackson/BsonParser.java
@@ -29,16 +29,12 @@
import java.util.UUID;
import java.util.regex.Pattern;
-import org.codehaus.jackson.Base64Variant;
-import org.codehaus.jackson.JsonLocation;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.JsonStreamContext;
-import org.codehaus.jackson.JsonToken;
-import org.codehaus.jackson.ObjectCodec;
-import org.codehaus.jackson.impl.JsonParserMinimalBase;
-import org.codehaus.jackson.type.TypeReference;
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.core.base.ParserBase;
+import com.fasterxml.jackson.core.io.IOContext;
+import com.fasterxml.jackson.core.json.JsonReadContext;
+import com.fasterxml.jackson.core.type.TypeReference;
import de.undercouch.bson4jackson.io.BoundedInputStream;
import de.undercouch.bson4jackson.io.ByteOrderUtil;
import de.undercouch.bson4jackson.io.CountingInputStream;
@@ -53,7 +49,7 @@
* Reads a BSON document from the provided input stream
* @author Michel Kraemer
*/
-public class BsonParser extends JsonParserMinimalBase {
+public class BsonParser extends ParserBase {
/**
* Defines toggable features
*/
@@ -116,14 +112,15 @@ public int getMask() {
/**
* Constructs a new parser
+ * @param ctxt the Jackson IO context
* @param jsonFeatures bit flag composed of bits that indicate which
- * {@link org.codehaus.jackson.JsonParser.Feature}s are enabled.
+ * {@link com.fasterxml.jackson.core.JsonParser.Feature}s are enabled.
* @param bsonFeatures bit flag composed of bits that indicate which
* {@link Feature}s are enabled.
* @param in the input stream to parse.
*/
- public BsonParser(int jsonFeatures, int bsonFeatures, InputStream in) {
- super(jsonFeatures);
+ public BsonParser(IOContext ctxt, int jsonFeatures, int bsonFeatures, InputStream in) {
+ super(ctxt, jsonFeatures);
_bsonFeatures = bsonFeatures;
_rawInputStream = in;
//only initialize streams here if document length isn't going to be honored
@@ -586,7 +583,7 @@ public String getCurrentName() throws IOException, JsonParseException {
}
@Override
- public JsonStreamContext getParsingContext() {
+ public JsonReadContext getParsingContext() {
//this parser does not use JsonStreamContext
return null;
}
@@ -731,6 +728,22 @@ protected void _handleEOF() throws JsonParseException {
_reportInvalidEOF();
}
+ @Override
+ protected boolean loadMore() throws IOException {
+ // We don't actually use this
+ return true;
+ }
+
+ @Override
+ protected void _finishString() throws IOException, JsonParseException {
+ // Not used
+ }
+
+ @Override
+ protected void _closeInput() throws IOException {
+ _rawInputStream.close();
+ }
+
/**
* Specifies what the parser is currently parsing (field name or value) or
* if it is done with the current element
View
2 src/main/java/de/undercouch/bson4jackson/io/StaticBuffers.java
@@ -23,7 +23,7 @@
* This class is a singleton, whereas the reference to the instance is hold
* in a {@link SoftReference} so buffers can be freed when they are not needed
* anymore.
- * @see org.codehaus.jackson.util.BufferRecycler
+ * @see com.fasterxml.jackson.core.util.BufferRecycler
* @author Michel Kraemer
*/
public class StaticBuffers {
View
2 src/main/java/de/undercouch/bson4jackson/serializers/BsonCalendarSerializer.java
@@ -14,8 +14,8 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
import java.util.Calendar;
View
2 src/main/java/de/undercouch/bson4jackson/serializers/BsonDateSerializer.java
@@ -14,8 +14,8 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
import java.util.Date;
View
3 src/main/java/de/undercouch/bson4jackson/serializers/BsonJavascriptSerializer.java
@@ -14,12 +14,11 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
import de.undercouch.bson4jackson.types.JavaScript;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
-import java.util.regex.Pattern;
/**
* Serializer for JavaScript
View
2 src/main/java/de/undercouch/bson4jackson/serializers/BsonObjectIdSerializer.java
@@ -14,9 +14,9 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
import de.undercouch.bson4jackson.types.ObjectId;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
View
2 src/main/java/de/undercouch/bson4jackson/serializers/BsonRegexSerializer.java
@@ -14,8 +14,8 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
import java.util.regex.Pattern;
View
10 src/main/java/de/undercouch/bson4jackson/serializers/BsonSerializer.java
@@ -14,12 +14,12 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.map.JsonSerializer;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
View
31 src/main/java/de/undercouch/bson4jackson/serializers/BsonSerializers.java
@@ -0,0 +1,31 @@
+package de.undercouch.bson4jackson.serializers;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.ser.Serializers;
+import de.undercouch.bson4jackson.types.JavaScript;
+import de.undercouch.bson4jackson.types.ObjectId;
+import de.undercouch.bson4jackson.types.Symbol;
+import de.undercouch.bson4jackson.types.Timestamp;
+
+import java.util.*;
+import java.util.regex.Pattern;
+
+/**
+ * Bson Serializers
+ *
+ * @author jroper
+ * @since 2.0
+ */
+public class BsonSerializers extends SimpleSerializers {
+
+ public BsonSerializers() {
+ addSerializer(UUID.class, new BsonUuidSerializer());
+ addSerializer(Date.class, new BsonDateSerializer());
+ addSerializer(Calendar.class, new BsonCalendarSerializer());
+ addSerializer(ObjectId.class, new BsonObjectIdSerializer());
+ addSerializer(Pattern.class, new BsonRegexSerializer());
+ addSerializer(JavaScript.class, new BsonJavaScriptSerializer());
+ addSerializer(Timestamp.class, new BsonTimestampSerializer());
+ addSerializer(Symbol.class, new BsonSymbolSerializer());
+ }
+}
View
3 src/main/java/de/undercouch/bson4jackson/serializers/BsonSymbolSerializer.java
@@ -14,12 +14,11 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
import de.undercouch.bson4jackson.types.Symbol;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
-import java.util.regex.Pattern;
/**
* Serializer for BSON Symbols
View
3 src/main/java/de/undercouch/bson4jackson/serializers/BsonTimestampSerializer.java
@@ -14,12 +14,11 @@
package de.undercouch.bson4jackson.serializers;
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonGenerator;
import de.undercouch.bson4jackson.types.Timestamp;
-import org.codehaus.jackson.map.SerializerProvider;
import java.io.IOException;
-import java.util.regex.Pattern;
/**
* Serializer for MongoDB Timestamps
View
6 src/main/java/de/undercouch/bson4jackson/serializers/BsonUuidSerializer.java
@@ -17,11 +17,7 @@
import java.io.IOException;
import java.util.UUID;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.map.SerializerProvider;
-
+import com.fasterxml.jackson.databind.SerializerProvider;
import de.undercouch.bson4jackson.BsonConstants;
import de.undercouch.bson4jackson.BsonGenerator;
View
153 src/main/java/de/undercouch/bson4jackson/serializers/SimpleSerializers.java
@@ -0,0 +1,153 @@
+package de.undercouch.bson4jackson.serializers;
+
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.databind.ser.Serializers;
+import com.fasterxml.jackson.databind.type.ClassKey;
+
+import java.util.HashMap;
+
+/**
+ * Copied from Jackson 1.7.3 until it's readded to 2.0
+ *
+ * Simple implementation {@link Serializers} which allows registration of
+ * serializers based on raw (type erased class).
+ * It can work well for basic bean and scalar type serializers, but is not
+ * a good fit for handling generic types (like {@link java.util.Map}s and {@link java.util.Collection}s).
+ *<p>
+ * Type registrations are assumed to be general; meaning that registration of serializer
+ * for a super type will also be used for handling subtypes, unless an exact match
+ * is found first. As an example, handler for {@link CharSequence} would also be used
+ * serializing {@link StringBuilder} instances, unless a direct mapping was found.
+ *
+ * @since 1.7
+ */
+public class SimpleSerializers extends Serializers.Base
+{
+ /**
+ * Class-based mappings that are used both for exact and
+ * sub-class matches.
+ */
+ protected HashMap<ClassKey,JsonSerializer<?>> _classMappings = null;
+
+ /**
+ * Interface-based matches.
+ */
+ protected HashMap<ClassKey,JsonSerializer<?>> _interfaceMappings = null;
+
+ /*
+ /**********************************************************
+ /* Life-cycle, construction and configuring
+ /**********************************************************
+ */
+
+ public SimpleSerializers() { }
+
+ /**
+ * Method for adding given serializer for type that {@link JsonSerializer#handledType}
+ * specifies (which MUST return a non-null class; and can NOT be {@link Object}, as a
+ * sanity check).
+ * For serializers that do not declare handled type, use the variant that takes
+ * two arguments.
+ *
+ * @param ser
+ */
+ public void addSerializer(JsonSerializer<?> ser)
+ {
+ // Interface to match?
+ Class<?> cls = ser.handledType();
+ if (cls == null || cls == Object.class) {
+ throw new IllegalArgumentException("JsonSerializer of type "+ser.getClass().getName()
+ +" does not define valid handledType() (use alternative registration method?)");
+ }
+ _addSerializer(cls, ser);
+ }
+
+ public <T> void addSerializer(Class<? extends T> type, JsonSerializer<T> ser)
+ {
+ _addSerializer(type, ser);
+ }
+
+ private void _addSerializer(Class<?> cls, JsonSerializer<?> ser)
+ {
+ ClassKey key = new ClassKey(cls);
+ // Interface or class type?
+ if (cls.isInterface()) {
+ if (_interfaceMappings == null) {
+ _interfaceMappings = new HashMap<ClassKey,JsonSerializer<?>>();
+ }
+ _interfaceMappings.put(key, ser);
+ } else { // nope, class:
+ if (_classMappings == null) {
+ _classMappings = new HashMap<ClassKey,JsonSerializer<?>>();
+ }
+ _classMappings.put(key, ser);
+ }
+ }
+
+ /*
+ /**********************************************************
+ /* Serializers implementation
+ /**********************************************************
+ */
+
+ @Override
+ public JsonSerializer<?> findSerializer(SerializationConfig config, JavaType type,
+ BeanDescription beanDesc, BeanProperty property)
+ {
+ Class<?> cls = type.getRawClass();
+ ClassKey key = new ClassKey(cls);
+ JsonSerializer<?> ser = null;
+
+ // First: direct match?
+ if (cls.isInterface()) {
+ if (_interfaceMappings != null) {
+ ser = _interfaceMappings.get(key);
+ if (ser != null) {
+ return ser;
+ }
+ }
+ } else {
+ if (_classMappings != null) {
+ ser = _classMappings.get(key);
+ if (ser != null) {
+ return ser;
+ }
+ // If not direct match, maybe super-class match?
+ for (Class<?> curr = cls; (curr != null); curr = curr.getSuperclass()) {
+ key.reset(curr);
+ ser = _classMappings.get(key);
+ if (ser != null) {
+ return ser;
+ }
+ }
+ }
+ }
+ // No direct match? How about super-interfaces?
+ if (_interfaceMappings != null) {
+ return _findInterfaceMapping(cls, key);
+ }
+ return null;
+ }
+
+ /*
+ /**********************************************************
+ /* Internal methods
+ /**********************************************************
+ */
+
+ protected JsonSerializer<?> _findInterfaceMapping(Class<?> cls, ClassKey key)
+ {
+ for (Class<?> iface : cls.getInterfaces()) {
+ key.reset(iface);
+ JsonSerializer<?> ser = _interfaceMappings.get(key);
+ if (ser != null) {
+ return ser;
+ }
+ ser = _findInterfaceMapping(iface, key);
+ if (ser != null) {
+ return ser;
+ }
+ }
+ return null;
+ }
+}
View
31 src/main/java/de/undercouch/bson4jackson/uuid/BsonUuidModule.java
@@ -14,26 +14,33 @@
package de.undercouch.bson4jackson.uuid;
-import java.util.UUID;
-
-import de.undercouch.bson4jackson.serializers.BsonUuidSerializer;
-import org.codehaus.jackson.Version;
-import org.codehaus.jackson.map.module.SimpleModule;
+import com.fasterxml.jackson.core.Version;
+import com.fasterxml.jackson.databind.Module;
+import de.undercouch.bson4jackson.serializers.BsonSerializers;
/**
* Module which registers a serializer that writes UUIDs as BSON binary fields
* with the UUID sub-type. Register with an ObjectMapper instance to enable this
* functionality.
+ *
* @author Ed Anuff
* @deprecated Use {@link de.undercouch.bson4jackson.BsonModule} instead to get all the custom serializers BSON requires
*/
@Deprecated
-public class BsonUuidModule extends SimpleModule {
- /**
- * Default constructor
- */
- public BsonUuidModule() {
- super("BsonUuidModule", new Version(0, 1, 0, "alpha"));
- addSerializer(UUID.class, new BsonUuidSerializer());
+public class BsonUuidModule extends Module {
+
+ @Override
+ public String getModuleName() {
+ return "BsonUuidModule";
+ }
+
+ @Override
+ public Version version() {
+ return new Version(0, 1, 0, "alpha");
+ }
+
+ @Override
+ public void setupModule(SetupContext context) {
+ context.addSerializers(new BsonSerializers());
}
}
View
4 src/test/java/de/undercouch/bson4jackson/BsonGeneratorTest.java
@@ -23,6 +23,8 @@
import java.util.*;
import java.util.regex.Pattern;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.ObjectMapper;
import de.undercouch.bson4jackson.types.JavaScript;
import de.undercouch.bson4jackson.types.ObjectId;
import de.undercouch.bson4jackson.types.Timestamp;
@@ -31,8 +33,6 @@
import org.bson.types.BSONTimestamp;
import org.bson.types.Code;
import org.bson.types.CodeWScope;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Test;
import de.undercouch.bson4jackson.io.DynamicOutputBuffer;
View
12 src/test/java/de/undercouch/bson4jackson/BsonParserTest.java
@@ -29,6 +29,10 @@
import java.util.UUID;
import java.util.regex.Pattern;
+import com.fasterxml.jackson.core.JsonNode;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationConfig;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.bson.BSONEncoder;
import org.bson.BSONObject;
import org.bson.BasicBSONObject;
@@ -37,10 +41,6 @@
import org.bson.types.Code;
import org.bson.types.CodeWScope;
import org.bson.types.Symbol;
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.JsonToken;
-import org.codehaus.jackson.map.DeserializationConfig;
-import org.codehaus.jackson.map.ObjectMapper;
import org.junit.Test;
import de.undercouch.bson4jackson.types.JavaScript;
@@ -211,10 +211,10 @@ public void parseEmbeddedDocumentAsTree() throws Exception {
assertEquals(JsonToken.FIELD_NAME, dec.nextToken());
assertEquals("Obj2", dec.getCurrentName());
assertEquals(JsonToken.START_OBJECT, dec.nextToken());
- JsonNode obj2 = dec.readValueAsTree();
+ JsonNode obj2 = dec.readValueAsTree();
assertEquals(1, obj2.size());
assertNotNull(obj2.get("Int64"));
- assertEquals(10L, obj2.get("Int64").getValueAsLong());
+ assertEquals(10L, obj2.get("Int64").getLongValue());
assertEquals(JsonToken.FIELD_NAME, dec.nextToken());
assertEquals("Obj3", dec.getCurrentName());

0 comments on commit a6c0bf5

Please sign in to comment.