Created
December 2, 2014 01:07
-
-
Save ovictorpinto/ec1725bcd598d5e871b0 to your computer and use it in GitHub Desktop.
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
import java.lang.reflect.Type; | |
import java.time.LocalDateTime; | |
import javax.enterprise.context.Dependent; | |
import com.google.gson.JsonElement; | |
import com.google.gson.JsonPrimitive; | |
import com.google.gson.JsonSerializationContext; | |
import com.google.gson.JsonSerializer; | |
/** | |
* Serializar to LocalDateTime | |
* @author victorpinto | |
* | |
*/ | |
@Dependent | |
public class LocalDateTimeGsonConverter implements JsonSerializer<LocalDateTime> { | |
@Override | |
public JsonElement serialize(LocalDateTime localDateTime, Type typeOfSrc, JsonSerializationContext context) { | |
String val = null; | |
if (localDateTime != null) { | |
val = localDateTime.toString(); | |
} | |
return new JsonPrimitive(val); | |
} | |
} |
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
import java.lang.reflect.Type; | |
import java.time.LocalDate; | |
import javax.enterprise.context.Dependent; | |
import com.google.gson.JsonElement; | |
import com.google.gson.JsonPrimitive; | |
import com.google.gson.JsonSerializationContext; | |
import com.google.gson.JsonSerializer; | |
/** | |
* Serializar to LocalDate | |
* @author victorpinto | |
* | |
*/ | |
@Dependent | |
public class LocalDateGsonConverter implements JsonSerializer<LocalDate> { | |
@Override | |
public JsonElement serialize(LocalDate localDate, Type typeOfSrc, JsonSerializationContext context) { | |
String val = null; | |
if (localDate != null) { | |
val = localDate.toString(); | |
} | |
return new JsonPrimitive(val); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment