/** * Generated by API Builder - https://www.apibuilder.io * Service version: 0.0.1 * User agent: apibuilder app.apibuilder.io/edsancha/survey-models/0.0.1/play_2_x_scala_3_standalone_json */ package com.edsancha.survey.models.v0.models { sealed trait Component extends _root_.scala.Product with _root_.scala.Serializable object Component { case object Label extends Component { override def toString = "label" } case object Image extends Component { override def toString = "image" } case object Nps extends Component { override def toString = "nps" } case object TextArea extends Component { override def toString = "textArea" } case object TextInput extends Component { override def toString = "textInput" } case object Radio extends Component { override def toString = "radio" } case object Checkbox extends Component { override def toString = "checkbox" } case object Grading extends Component { override def toString = "grading" } case object Grading0to10 extends Component { override def toString = "grading0to10" } case object Grading1to10 extends Component { override def toString = "grading1to10" } /** * UNDEFINED captures values that are sent either in error or * that were added by the server after this library was * generated. We want to make it easy and obvious to users of * this library to handle this case gracefully. * * We use all CAPS for the variable name to avoid collisions * with the camel cased values above. */ final case class UNDEFINED(override val toString: String) extends Component /** * all returns a list of all the valid, known values. We use * lower case to avoid collisions with the camel cased values * above. */ val all: scala.List[Component] = scala.List(Label, Image, Nps, TextArea, TextInput, Radio, Checkbox, Grading, Grading0to10, Grading1to10) private val byName: Map[String, Component] = all.map(x => x.toString.toLowerCase -> x).toMap def apply(value: String): Component = fromString(value).getOrElse(UNDEFINED(value)) def fromString(value: String): _root_.scala.Option[Component] = byName.get(value.toLowerCase) } } package com.edsancha.survey.models.v0.models { package object json { import play.api.libs.json.__ import play.api.libs.json.JsString import play.api.libs.json.Writes import play.api.libs.functional.syntax._ import com.edsancha.survey.models.v0.models.json._ private[v0] implicit val jsonReadsUUID: play.api.libs.json.Reads[_root_.java.util.UUID] = __.read[String].map { str => _root_.java.util.UUID.fromString(str) } private[v0] implicit val jsonWritesUUID: play.api.libs.json.Writes[_root_.java.util.UUID] = (x: _root_.java.util.UUID) => play.api.libs.json.JsString(x.toString) private[v0] implicit val jsonReadsJodaDateTime: play.api.libs.json.Reads[_root_.org.joda.time.DateTime] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseDateTime(str) } private[v0] implicit val jsonWritesJodaDateTime: play.api.libs.json.Writes[_root_.org.joda.time.DateTime] = (x: _root_.org.joda.time.DateTime) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.dateTime.print(x)) } private[v0] implicit val jsonReadsJodaLocalDate: play.api.libs.json.Reads[_root_.org.joda.time.LocalDate] = __.read[String].map { str => _root_.org.joda.time.format.ISODateTimeFormat.dateTimeParser.parseLocalDate(str) } private[v0] implicit val jsonWritesJodaLocalDate: play.api.libs.json.Writes[_root_.org.joda.time.LocalDate] = (x: _root_.org.joda.time.LocalDate) => { play.api.libs.json.JsString(_root_.org.joda.time.format.ISODateTimeFormat.date.print(x)) } implicit val jsonReadsSurveyModelsComponent: play.api.libs.json.Reads[com.edsancha.survey.models.v0.models.Component] = new play.api.libs.json.Reads[com.edsancha.survey.models.v0.models.Component] { def reads(js: play.api.libs.json.JsValue): play.api.libs.json.JsResult[com.edsancha.survey.models.v0.models.Component] = { js match { case v: play.api.libs.json.JsString => play.api.libs.json.JsSuccess(com.edsancha.survey.models.v0.models.Component(v.value)) case _ => { (js \ "value").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(com.edsancha.survey.models.v0.models.Component(v)) case _: play.api.libs.json.JsError => (js \ "component").validate[String] match { case play.api.libs.json.JsSuccess(v, _) => play.api.libs.json.JsSuccess(com.edsancha.survey.models.v0.models.Component(v)) case err: play.api.libs.json.JsError => err } } } } } } def jsonWritesSurveyModelsComponent(obj: com.edsancha.survey.models.v0.models.Component) = { play.api.libs.json.JsString(obj.toString) } def jsObjectComponent(obj: com.edsancha.survey.models.v0.models.Component) = { play.api.libs.json.Json.obj("value" -> play.api.libs.json.JsString(obj.toString)) } implicit def jsonWritesSurveyModelsComponent: play.api.libs.json.Writes[Component] = { (obj: com.edsancha.survey.models.v0.models.Component) => { com.edsancha.survey.models.v0.models.json.jsonWritesSurveyModelsComponent(obj) } } } }