Skip to content

Commit e980981

Browse files
committed
java8 - introduced new restx-jongo-java8 for java8 datetime serialization support with jongo.
This fixes #204
1 parent b4d8650 commit e980981

7 files changed

Lines changed: 139 additions & 0 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@
610610
</activation>
611611
<modules>
612612
<module>restx-core-java8</module>
613+
<module>restx-jongo-java8</module>
613614
<module>restx-specs-tests-java8</module>
614615
<module>restx-samplest-java8</module>
615616
</modules>

restx-jongo-java8/md.restx.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"parent": "io.restx:restx-parent:${restx.version}",
3+
"module": "io.restx:restx-jongo-java8:${restx.version}",
4+
5+
"properties": {
6+
"@files": ["../restx.build.properties.json"],
7+
"java.version": "1.8"
8+
},
9+
10+
"dependencies": {
11+
"compile": [
12+
"io.restx:restx-factory:${restx.version}",
13+
"io.restx:restx-jongo:${restx.version}"
14+
]
15+
}
16+
}

restx-jongo-java8/module.ivy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<ivy-module version="2.0" xmlns:ea="http://www.easyant.org">
2+
<info organisation="io.restx" module="restx-jongo-java8" revision="0.35" status="integration">
3+
<ea:build organisation="org.apache.easyant.buildtypes" module="build-std-java" revision="0.9"
4+
compile.java.source.version="1.8"
5+
compile.java.target.version="1.8"
6+
/>
7+
</info>
8+
<configurations>
9+
<conf name="default"/>
10+
<conf name="runtime"/>
11+
<conf name="test"/>
12+
</configurations>
13+
<publications>
14+
<artifact type="jar"/>
15+
</publications>
16+
<dependencies>
17+
<dependency org="io.restx" name="restx-factory" rev="latest.integration" conf="default" />
18+
<dependency org="io.restx" name="restx-jongo" rev="latest.integration" conf="default" />
19+
</dependencies>
20+
</ivy-module>

restx-jongo-java8/pom.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.restx</groupId>
9+
<artifactId>restx-parent</artifactId>
10+
<version>0.35-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>restx-jongo-java8</artifactId>
14+
<name>restx-jongo-java8</name>
15+
16+
<properties>
17+
<maven.compiler.source>1.8</maven.compiler.source>
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.restx</groupId>
24+
<artifactId>restx-factory</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>io.restx</groupId>
28+
<artifactId>restx-jongo</artifactId>
29+
</dependency>
30+
</dependencies>
31+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package restx.jongo;
2+
3+
import com.fasterxml.jackson.core.JsonParser;
4+
import com.fasterxml.jackson.core.JsonProcessingException;
5+
import com.fasterxml.jackson.databind.DeserializationContext;
6+
import com.fasterxml.jackson.databind.JsonDeserializer;
7+
import com.fasterxml.jackson.databind.SerializerProvider;
8+
import com.fasterxml.jackson.databind.module.SimpleModule;
9+
import de.undercouch.bson4jackson.BsonGenerator;
10+
import de.undercouch.bson4jackson.serializers.BsonSerializer;
11+
12+
import java.io.IOException;
13+
import java.time.Instant;
14+
import java.util.Date;
15+
16+
public class BsonJSR310Module extends SimpleModule {
17+
public BsonJSR310Module() {
18+
super("BsonJSR310Module");
19+
20+
addSerializer(Instant.class, new BsonSerializer<Instant>() {
21+
@Override
22+
public void serialize(Instant date, BsonGenerator bsonGenerator, SerializerProvider serializerProvider)
23+
throws IOException {
24+
if (date == null) {
25+
serializerProvider.defaultSerializeNull(bsonGenerator);
26+
} else {
27+
bsonGenerator.writeDateTime(new Date(date.toEpochMilli()));
28+
}
29+
}
30+
});
31+
32+
addDeserializer(Instant.class, new JsonDeserializer<Instant>() {
33+
@Override
34+
public Instant deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
35+
Date date = (Date) jp.getEmbeddedObject();
36+
return Instant.ofEpochMilli(date.getTime());
37+
}
38+
});
39+
}
40+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package restx.jongo;
2+
3+
import org.jongo.Mapper;
4+
import org.jongo.marshall.jackson.JacksonMapper;
5+
import restx.factory.Module;
6+
import restx.factory.Provides;
7+
import restx.jackson.BsonJodaTimeModule;
8+
import restx.jackson.Views;
9+
10+
import javax.inject.Named;
11+
12+
/**
13+
* User: xavierhanin
14+
* Date: 1/19/13
15+
* Time: 12:12 AM
16+
*/
17+
@Module(priority = -10)
18+
public class JongoJava8Module {
19+
@Provides @Named("Mapper")
20+
public Mapper mapper() {
21+
return new JacksonMapper.Builder()
22+
.registerModule(new BsonJodaTimeModule()) // to keep compatibility with joda time
23+
.registerModule(new BsonJSR310Module())
24+
.withView(Views.Private.class)
25+
.build();
26+
}
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package samplest.autostartable;
2+
3+
public class Blah {
4+
}

0 commit comments

Comments
 (0)