-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
java8 - introduced new restx-jongo-java8 for java8 datetime serializa…
…tion support with jongo. This fixes #204
- Loading branch information
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
40 changes: 40 additions & 0 deletions
40
restx-jongo-java8/src/main/java/restx/jongo/BsonJSR310Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
restx-jongo-java8/src/main/java/restx/jongo/JongoJava8Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
restx-samplest/src/main/java/samplest/autostartable/Blah.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package samplest.autostartable; | ||
|
||
public class Blah { | ||
} |