Permalink
Browse files

java8 - introduced new restx-jongo-java8 for java8 datetime serializa…

…tion support with jongo.

This fixes #204
  • Loading branch information...
fcamblor committed Aug 22, 2017
1 parent b4d8650 commit e9809815be71162e99c580e3154d34db91a85418
@@ -610,6 +610,7 @@
</activation>
<modules>
<module>restx-core-java8</module>
<module>restx-jongo-java8</module>
<module>restx-specs-tests-java8</module>
<module>restx-samplest-java8</module>
</modules>
@@ -0,0 +1,16 @@
{
"parent": "io.restx:restx-parent:${restx.version}",
"module": "io.restx:restx-jongo-java8:${restx.version}",
"properties": {
"@files": ["../restx.build.properties.json"],
"java.version": "1.8"
},
"dependencies": {
"compile": [
"io.restx:restx-factory:${restx.version}",
"io.restx:restx-jongo:${restx.version}"
]
}
}
@@ -0,0 +1,20 @@
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
<info organisation="io.restx" module="restx-jongo-java8" revision="0.35" status="integration">
<ea:build organisation="org.apache.easyant.buildtypes" module="build-std-java" revision="0.9"
compile.java.source.version="1.8"
compile.java.target.version="1.8"
/>
</info>
<configurations>
<conf name="default"/>
<conf name="runtime"/>
<conf name="test"/>
</configurations>
<publications>
<artifact type="jar"/>
</publications>
<dependencies>
<dependency org="io.restx" name="restx-factory" rev="latest.integration" conf="default" />
<dependency org="io.restx" name="restx-jongo" rev="latest.integration" conf="default" />
</dependencies>
</ivy-module>
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.restx</groupId>
<artifactId>restx-parent</artifactId>
<version>0.35-SNAPSHOT</version>
</parent>
<artifactId>restx-jongo-java8</artifactId>
<name>restx-jongo-java8</name>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-factory</artifactId>
</dependency>
<dependency>
<groupId>io.restx</groupId>
<artifactId>restx-jongo</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,40 @@
package restx.jongo;
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.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;
import java.util.Date;
public class BsonJSR310Module extends SimpleModule {
public BsonJSR310Module() {
super("BsonJSR310Module");
addSerializer(Instant.class, new BsonSerializer<Instant>() {
@Override
public void serialize(Instant date, BsonGenerator bsonGenerator, SerializerProvider serializerProvider)
throws IOException {
if (date == null) {
serializerProvider.defaultSerializeNull(bsonGenerator);
} else {
bsonGenerator.writeDateTime(new Date(date.toEpochMilli()));
}
}
});
addDeserializer(Instant.class, new JsonDeserializer<Instant>() {
@Override
public Instant deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
Date date = (Date) jp.getEmbeddedObject();
return Instant.ofEpochMilli(date.getTime());
}
});
}
}
@@ -0,0 +1,27 @@
package restx.jongo;
import org.jongo.Mapper;
import org.jongo.marshall.jackson.JacksonMapper;
import restx.factory.Module;
import restx.factory.Provides;
import restx.jackson.BsonJodaTimeModule;
import restx.jackson.Views;
import javax.inject.Named;
/**
* User: xavierhanin
* Date: 1/19/13
* Time: 12:12 AM
*/
@Module(priority = -10)
public class JongoJava8Module {
@Provides @Named("Mapper")
public Mapper mapper() {
return new JacksonMapper.Builder()
.registerModule(new BsonJodaTimeModule()) // to keep compatibility with joda time
.registerModule(new BsonJSR310Module())
.withView(Views.Private.class)
.build();
}
}
@@ -0,0 +1,4 @@
package samplest.autostartable;
public class Blah {
}

0 comments on commit e980981

Please sign in to comment.