Add modified mongo-jackson-codec files to repository

This will mean we no longer depend on our custom version of the codec
being available at compile time - we instead depend on the public version
and 'apply' our changes at compile time with the maven shade plugin. The
package-info.java file describes the changes (+ motivation for these changes)
made to the public library.
This commit is contained in:
Colin McDonald 2016-10-20 22:11:57 -04:00
parent 1b343f98f7
commit 9a4ab71b5d
5 changed files with 65 additions and 1 deletions

View File

@ -117,7 +117,8 @@
<groupId>fr.javatic.mongo</groupId>
<artifactId>mongo-jackson-codec</artifactId>
<version>3.2.0__0.4</version>
<!-- version should be kept at 3.2.0__0.4 because of our modifiers we make to this lib -->
<!-- version should be kept at 3.2.0__0.4 to ensure
compatability with overriden classes in this codebase -->
</dependency>
<dependency>
<groupId>de.undercouch</groupId>

View File

@ -0,0 +1,7 @@
package fr.javatic.mongo.jacksonCodec;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface Entity {}

View File

@ -0,0 +1,25 @@
package fr.javatic.mongo.jacksonCodec;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.bson.codecs.Codec;
import org.bson.codecs.configuration.CodecProvider;
import org.bson.codecs.configuration.CodecRegistry;
public class JacksonCodecProvider implements CodecProvider {
private final ObjectMapper bsonObjectMapper;
public JacksonCodecProvider(final ObjectMapper bsonObjectMapper) {
this.bsonObjectMapper = bsonObjectMapper;
}
@Override
public <T> Codec<T> get(final Class<T> type, final CodecRegistry registry) {
if (type.getAnnotationsByType(Entity.class).length > 0) {
return new JacksonCodec<>(bsonObjectMapper, registry, type);
} else {
return null;
}
}
}

View File

@ -0,0 +1,16 @@
package fr.javatic.mongo.jacksonCodec.objectId;
import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonProperty("_id")
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonDeserialize
public @interface Id {}

View File

@ -0,0 +1,15 @@
/**
* Uses maven-shade-plugin to override classes in fr.javatic.mongo:mongo-jackson-codec
*
* Similar to what's done with org.apache.commons:commons-pool2 in qLib, we modify and create
* classes in this codebase in order to override fr.javatic.mongo.jacksonCodec classes in the final jar.
*
* These changes add an @Entity annotation and fix serializers in the @Id annotation.
* Without these changes the mongodb driver fails to deserialize documents. Additionally, an @Entity
* annotation allows us to selectively include types, instead of mapping ALL types.
*
* The files present here were copied from:
* https://github.com/FrozenOrb/mongo-jackson-codec/commit/b3a168e5f5f7464c3721fd9ebc81a4cca7d4db2f (entire common)
* https://github.com/FrozenOrb/mongo-jackson-codec/commit/20c161337900bb7daabd3d9d99ead1be35c0c41b (non-build files only)
*/
package fr.javatic.mongo.jacksonCodec;