Skip to content

Instantly share code, notes, and snippets.

@d6y
Created May 19, 2020 11:47
Show Gist options
  • Save d6y/5455c7e4129456da6be819b90b9cb449 to your computer and use it in GitHub Desktop.
Save d6y/5455c7e4129456da6be819b90b9cb449 to your computer and use it in GitHub Desktop.
piusher overriding date time format
// 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