Permalink
Browse files

Revert "aligned over bson4jackson 2.8.0 which should fix weird date d…

…eserialization errors"

This reverts commit b1c4dd5.
  • Loading branch information...
fcamblor committed Feb 25, 2018
1 parent 2469d34 commit b3282a31011a710b178c9029c6aae8624bfc8ecf
View
@@ -84,7 +84,7 @@
<!-- Mongo modules -->
<mongo-java-driver.version>3.4.0</mongo-java-driver.version>
<bson4jackson.version>2.8.0</bson4jackson.version>
<bson4jackson.version>2.7.0</bson4jackson.version>
<jongo.version>1.3.0</jongo.version>
<de.flapdoodle.embed.version>1.42</de.flapdoodle.embed.version>
@@ -1,14 +1,13 @@
package restx.jongo;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import de.undercouch.bson4jackson.BsonGenerator;
import de.undercouch.bson4jackson.serializers.BsonSerializer;
import java.io.IOException;
import java.time.Instant;
@@ -18,20 +17,14 @@
public BsonJSR310Module() {
super("BsonJSR310Module");
addSerializer(Instant.class, new JsonSerializer<Instant>() {
addSerializer(Instant.class, new BsonSerializer<Instant>() {
@Override
public void serialize(Instant date, JsonGenerator gen, SerializerProvider provider)
public void serialize(Instant date, BsonGenerator bsonGenerator, SerializerProvider serializerProvider)
throws IOException {
if (date == null) {
provider.defaultSerializeNull(gen);
serializerProvider.defaultSerializeNull(bsonGenerator);
} else {
long epochMillis = date.toEpochMilli();
if (gen instanceof BsonGenerator) {
BsonGenerator bgen = (BsonGenerator)gen;
bgen.writeDateTime(new Date(epochMillis));
} else {
gen.writeNumber(epochMillis);
}
bsonGenerator.writeDateTime(new Date(date.toEpochMilli()));
}
}
});
View
@@ -22,7 +22,7 @@
<dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.8.10" conf="default" />
<dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.8.10" conf="default" />
<dependency org="com.fasterxml.jackson.datatype" name="jackson-datatype-joda" rev="2.8.10" conf="default" />
<dependency org="de.undercouch" name="bson4jackson" rev="2.8.0" conf="default" />
<dependency org="de.undercouch" name="bson4jackson" rev="2.7.0" conf="default" />
<dependency org="org.mongodb" name="mongo-java-driver" rev="3.4.0" conf="default" />
<dependency org="org.jongo" name="jongo" rev="1.3.0" conf="default" />
<dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="default" />
@@ -1,15 +1,13 @@
package restx.jackson;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import de.undercouch.bson4jackson.BsonGenerator;
import org.joda.time.DateMidnight;
import de.undercouch.bson4jackson.serializers.BsonSerializer;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@@ -25,31 +23,25 @@
public BsonJodaTimeModule() {
super("BsonJodaTimeModule");
addSerializer(org.joda.time.DateMidnight.class, new JsonSerializer<DateMidnight>() {
addSerializer(org.joda.time.DateMidnight.class, new BsonSerializer<org.joda.time.DateMidnight>() {
@Override
public void serialize(org.joda.time.DateMidnight date, JsonGenerator gen, SerializerProvider provider)
public void serialize(org.joda.time.DateMidnight date, BsonGenerator bsonGenerator, SerializerProvider serializerProvider)
throws IOException {
if (date == null) {
provider.defaultSerializeNull(gen);
} else if (gen instanceof BsonGenerator) {
BsonGenerator bgen = (BsonGenerator)gen;
bgen.writeDateTime(date.toDate());
serializerProvider.defaultSerializeNull(bsonGenerator);
} else {
gen.writeNumber(date.getMillis());
bsonGenerator.writeDateTime(date.toDate());
}
}
});
addSerializer(DateTime.class, new JsonSerializer<DateTime>() {
addSerializer(DateTime.class, new BsonSerializer<DateTime>() {
@Override
public void serialize(DateTime date, JsonGenerator gen, SerializerProvider provider)
public void serialize(DateTime date, BsonGenerator bsonGenerator, SerializerProvider serializerProvider)
throws IOException {
if (date == null) {
provider.defaultSerializeNull(gen);
} else if (gen instanceof BsonGenerator) {
BsonGenerator bgen = (BsonGenerator)gen;
bgen.writeDateTime(date.toDate());
serializerProvider.defaultSerializeNull(bsonGenerator);
} else {
gen.writeNumber(date.getMillis());
bsonGenerator.writeDateTime(date.toDate());
}
}
});
@@ -28,7 +28,7 @@
"javax.inject.version": "1",
"mongo-java-driver.version": "3.4.0",
"bson4jackson.version": "2.8.0",
"bson4jackson.version": "2.7.0",
"jongo.version": "1.3.0",
"servlet-api.version": "2.5",

0 comments on commit b3282a3

Please sign in to comment.