Created
May 19, 2020 11:47
-
-
Save d6y/5455c7e4129456da6be819b90b9cb449 to your computer and use it in GitHub Desktop.
piusher overriding date time format
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
// Override the default LocalDateTime formatting | |
// (the default splits out each date.time element as a seperate field: hour, minute, day, etc) | |
def newInstance(url: String): Pusher = { | |
import com.google.gson._ | |
import java.lang.reflect.Type | |
val localDateTimeSerializer: JsonSerializer[LocalDateTime] = new JsonSerializer[LocalDateTime] { | |
def serialize(src: LocalDateTime, typeOfSrc: Type, context: JsonSerializationContext): JsonElement = | |
new JsonPrimitive(src.toString()) | |
} | |
val gson = new GsonBuilder() | |
.registerTypeAdapter(classOf[LocalDateTime], localDateTimeSerializer) | |
.create() | |
val pusher = new Pusher(url) | |
pusher.setGsonSerialiser(gson) | |
pusher | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment