WIP desktop client for Chatto reimplemented in ScalaFX and Sapphire Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
2.2 KiB

package wow.doge.chatto.service
import org.json4s.CustomSerializer
import org.json4s._
import java.time.Instant
// import org.json4s.JsonAST._
import org.json4s.JsonDSL._
// class ParentSerializer extends Serializer[Parent] {
// private val ParentClass = classOf[Parent]
// implicit val formats = DefaultFormats
// def deserialize(implicit format: Formats): PartialFunction[(TypeInfo, JValue), Parent] = {
// case (TypeInfo(ParentClass, _), json) => json match {
// case JObject(JField("kind", JString(kind)) :: _) => kind match {
// case "first_type" => json.extract[ChildClassOne]
// case "second_type" => json.extract[ChildClassTwo]
// }
// case _ => throw new MappingException("Invalid kind")
// }
// }
// def serialize(implicit format: Formats): PartialFunction[Any, JValue] = Map()
// }
// class MyJInstantSerializer extends Serializer[Instant] {
// implicit val formats = DefaultFormats
// def deserialize(
// implicit format: Formats
// ): PartialFunction[(TypeInfo, JValue), Instant] = {
// case (_, JString(d)) => Instant.parse(d)
// case (_, JNull) => null
// }
// def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
// case d: Instant => JString(d.toString())
// }
// }
// class MyJInstantSerializer
// extends CustomSerializer[Instant](implicit format =>
// (
// {
// // case JInt(d) => Instant.ofEpochMilli(d.toLong)
// case JString(d) => Instant.parse(d)
// case JNull => null
// }, {
// // case d: Instant => JInt(d.toEpochMilli)
// case d: Instant => JString(d.toString())
// }
// )
// )
// import java.time.ZonedDateTime
// import java.time.format.DateTimeFormatter
// a custom serializer has two partial functions, one
// for serializing and one for deserializing
// case object ZDTSerializer
// extends CustomSerializer[ZonedDateTime](format =>
// ({
// case JString(s) => ZonedDateTime.parse(s)
// }, {
// case zdt: ZonedDateTime =>
// JString(
// zdt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXX"))
// )
// })
// )