
behaviors.serialization.ThirtyOneActionSerialization.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cards_2.13 Show documentation
Show all versions of cards_2.13 Show documentation
Scala library for card-playing functionality, including games Blackjack and Thirty-One
The newest version!
package cards.behaviors.serialization
import cards.behaviors.serialization.Serialization
import cards.classes.actions.{ Action, Actions }
import cards.classes.actions.ThirtyOneAction._
import play.api.libs.json. { Json, JsSuccess, Format }
import com.fasterxml.jackson.core.JsonParseException
trait ThirtyOneActionSerialization extends Serialization[Action[ThirtyOneAction]] {
override def parse(json: String): Either[String, Seq[Action[ThirtyOneAction]]] = try {
Json.parse(json).validate[Actions[ThirtyOneAction]] match {
case JsSuccess(as, _) => Right(as.actions)
case e => Left(s"Error occurred: ${e.toString()}")
}
} catch {
case e: JsonParseException => Left(e.getMessage())
}
override def json(items: Seq[Action[ThirtyOneAction]]): String = Actions(items).toString()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy