forked from arnaud-castelltort/play-Jug
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* | ||
*/ | ||
package utils; | ||
|
||
import java.lang.reflect.Type; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import com.google.gson.InstanceCreator; | ||
import com.google.gson.JsonDeserializationContext; | ||
import com.google.gson.JsonDeserializer; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParseException; | ||
import com.google.gson.JsonPrimitive; | ||
import com.google.gson.JsonSerializationContext; | ||
import com.google.gson.JsonSerializer; | ||
|
||
/** | ||
* @author eric | ||
*/ | ||
public class DateTypeAdapter implements InstanceCreator, JsonSerializer, JsonDeserializer { | ||
|
||
@Override | ||
public Object createInstance(Type type) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public JsonElement serialize(Object obj, Type type, JsonSerializationContext ctx) { | ||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
JsonElement ele = new JsonPrimitive(sdf.format((Date)obj)); | ||
return ele; | ||
} | ||
|
||
@Override | ||
public Object deserialize(JsonElement ele, Type type, JsonDeserializationContext ctx) throws JsonParseException { | ||
return null; | ||
} | ||
} |
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