本文整理汇总了Scala中play.api.libs.json.OFormat类的典型用法代码示例。如果您正苦于以下问题:Scala OFormat类的具体用法?Scala OFormat怎么用?Scala OFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MenuPerDayPerPersonForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.UUID
import play.api.data.Form
import play.api.data.Forms.{ mapping, text, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class MenuPerDayPerPersonForm(
menuPerDayUuid: List[UUID],
menuDate: List[String]
)
object MenuPerDayPerPersonForm {
implicit val menuPerDayPerPersonFormFormat: OFormat[MenuPerDayPerPersonForm] = Json.format[MenuPerDayPerPersonForm]
val menuPerDayPerPersonForm = Form(
mapping(
"menuPerDayUuid" -> list(of[UUID]),
"menuDate" -> list(text)
)(MenuPerDayPerPersonForm.apply)(MenuPerDayPerPersonForm.unapply)
)
}
示例2: User
//设置package包名称以及导入依赖的类
package io.skul.katebin
import io.skul.katebin.logic.Secure
import play.api.libs.json.{Json, OFormat}
import play.api.mvc.{Cookie => Co}
case class User(id: String, username: String, password: String)
case class Note(id: String, text: String, nodeId: String, title: String, date: Long, tags: List[String])
case class Node(id: String, name: String, children: List[Node])
case class Space(id: String, name: String, ownerId: String, users: List[String], root: Node)
case class Creden(username: String, password: String)
case class Cookie(value: String, userId: String) {
private val cookieMaxAge = Some(60 * 60 * 24 * 365)
def toHttp: Co = Co(Secure.cookie, value, maxAge = cookieMaxAge, httpOnly = true)
}
object Models {
implicit val userFormat = Json.format[User]
implicit val noteFormat = Json.format[Note]
implicit val nodeFormat = Json.format[Node]
implicit val spaceFormat = Json.format[Space]
implicit val credenFormat: OFormat[Creden] = Json.format[Creden]
implicit val cookieFormat: OFormat[Cookie] = Json.format[Cookie]
}
示例3: Task
//设置package包名称以及导入依赖的类
package models
import com.github.stonexx.play.mvc.binders.enum._
import com.github.stonexx.scala.data.OrderedEnumeration
import play.api.libs.json.{Json, OFormat}
import play.api.mvc.{PathBindable, QueryStringBindable}
case class Task(id: Option[Long], label: Option[String])
object Task {
implicit val jsonFormat: OFormat[Task] = Json.format[Task]
object forms {
import play.api.data._
import play.api.data.Forms._
val labelForm = Form(
"label" -> nonEmptyText(maxLength = 20)
)
object Sorts extends OrderedEnumeration {
type Sorts = Value
val Id = Value
val Label = Value
implicit val pathBindable : PathBindable[Ordered] = enumOrderedPathBindable(this)
implicit val queryStringBindable: QueryStringBindable[Ordered] = enumOrderedQueryStringBindable(this)
}
}
}
示例4: Cat
//设置package包名称以及导入依赖的类
package models
import com.github.stonexx.play.json.enum._
import play.api.libs.json.{Format, Json, OFormat}
case class Cat(
name: String,
color: String,
flag: Boolean,
state: Cat.State.Value
)
object Cat {
object State extends Enumeration {
type State = Option
val Bad = Option("The bad")
val Normal = Option("The normal")
val Good = Option("The good")
val VeryGood = Option("The very good")
protected case class Option(label: String) extends super.Val()
implicit def toOption(value: Value): Option = value.asInstanceOf[Option]
implicit val jsonFormat: Format[Value] = enumFormat(this)
}
implicit val jsonFormat: OFormat[Cat] = Json.format[Cat]
object forms {
import com.github.stonexx.play.data.forms.enum._
import play.api.data._
import play.api.data.Forms._
final val catForm = Form(
mapping(
"name" -> text,
"color" -> text,
"flag" -> ignored(true),
"state" -> enum(Cat.State)
)(Cat.apply)(Cat.unapply)
)
}
}
示例5: Dish
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.models
import java.util.UUID
import play.api.libs.json.{ Json, OFormat }
case class Dish (
uuid: UUID = UUID.randomUUID(),
name: String,
description: String,
isVegetarian: Boolean = false,
hasSeaFood: Boolean = false,
hasPork: Boolean = false,
hasBeef: Boolean = false,
hasChicken: Boolean = false,
isGlutenFree: Boolean = false,
hasLactose: Boolean = false,
remarks: Option[String] = None
)
case class DishIsSelected (
uuid: UUID = UUID.randomUUID(),
name: String,
isSelected: Boolean
)
object Dish {
implicit val dishFormat: OFormat[Dish] = Json.format[Dish]
}
示例6: MenuPerDayForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.{ Date, UUID }
import play.api.data.Form
import play.api.data.Forms.{ mapping, of, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class MenuPerDayForm(
menuUuid: UUID,
date: Date
)
object MenuPerDayForm {
implicit val menuPerDayFormFormat: OFormat[MenuPerDayForm] = Json.format[MenuPerDayForm]
val menuPerDayForm = Form(
mapping(
"menuUuid" -> of[UUID],
"date" -> date(pattern = "dd-MM-yyyy")
)(MenuPerDayForm.apply)(MenuPerDayForm.unapply)
)
}
case class ListMenusPerDayForm(listUuids: List[UUID], dateStart: Date, dateEnd: Date)
object ListMenusPerDayForm {
val listMenusPerDayForm = Form(
mapping(
"uuid" -> list(of[UUID]),
"dateStart" -> date(pattern = "dd-MM-yyyy"),
"dateEnd" -> date(pattern = "dd-MM-yyyy")
)(ListMenusPerDayForm.apply)(ListMenusPerDayForm.unapply)
)
}
case class FilterMenusPerDayForm(dateStart: Date, dateEnd: Date)
object FilterMenusPerDayForm {
val filterMenusPerDayForm = Form(
mapping(
"dateStart" -> date(pattern = "dd-MM-yyyy"),
"dateEnd" -> date(pattern = "dd-MM-yyyy")
)(FilterMenusPerDayForm.apply)(FilterMenusPerDayForm.unapply)
)
}
示例7: ProfileForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import play.api.data.Form
import play.api.data.Forms.{ mapping, optional, text, _ }
import play.api.libs.json.{ Json, OFormat }
case class ProfileForm(
vegetarian: Boolean,
seaFoodRestriction: Boolean,
porkRestriction: Boolean,
beefRestriction: Boolean,
chickenRestriction: Boolean,
glutenRestriction: Boolean,
lactoseRestriction: Boolean,
otherRestriction: Option[String]
)
object ProfileForm {
implicit val profileFormFormat: OFormat[DishForm] = Json.format[DishForm]
val profileForm = Form(
mapping(
"vegetarian" -> boolean,
"seaFoodRestriction" -> boolean,
"porkRestriction" -> boolean,
"beefRestriction" -> boolean,
"chickenRestriction" -> boolean,
"glutenRestriction" -> boolean,
"lactoseRestriction" -> boolean,
"otherRestriction" -> optional(text)
)(ProfileForm.apply)(ProfileForm.unapply)
)
}
示例8: MenuForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.UUID
import play.api.data.Form
import play.api.data.Forms.{ list, mapping, of, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class MenuForm(
menuName: String,
dishesUuid: List[UUID]
)
object MenuForm {
implicit val menuFormFormat: OFormat[MenuForm] = Json.format[MenuForm]
val menuForm = Form(
mapping(
"menuName" -> nonEmptyText,
"dishesUuid" -> list(of[UUID])
)(MenuForm.apply)(MenuForm.unapply)
)
}
case class ListMenusForm(listUuids: List[UUID])
object ListMenusForm {
val listMenusForm = Form(
mapping(
"uuid" -> list(of[UUID])
)(ListMenusForm.apply)(ListMenusForm.unapply)
)
}
示例9: DishForm
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.viewModels
import java.util.UUID
import play.api.data.Form
import play.api.data.Forms.{ mapping, optional, text, _ }
import play.api.data.format.Formats._
import play.api.libs.json.{ Json, OFormat }
case class DishForm (
name: String,
description: String,
isVegetarian: Boolean = false,
hasSeaFood: Boolean = false,
hasPork: Boolean = false,
hasBeef: Boolean = false,
hasChicken: Boolean = false,
isGlutenFree: Boolean = false,
hasLactose: Boolean = false,
remarks: Option[String] = None
)
object DishForm {
implicit val dishFormFormat: OFormat[DishForm] = Json.format[DishForm]
val dishForm = Form(
mapping(
"name" -> nonEmptyText,
"description" -> nonEmptyText,
"isVegetarian" -> boolean,
"hasSeaFood" -> boolean,
"hasPork" -> boolean,
"hasBeef" -> boolean,
"hasChicken" -> boolean,
"isGlutenFree" -> boolean,
"hasLactose" -> boolean,
"remarks" -> optional(text)
)(DishForm.apply)(DishForm.unapply)
)
}
case class ListDishesForm(listUuids: List[UUID])
object ListDishesForm {
val listDishesForm = Form(
mapping(
"uuid" -> list(of[UUID])
)(ListDishesForm.apply)(ListDishesForm.unapply)
)
}
示例10: Croissant
//设置package包名称以及导入依赖的类
package models
import java.time.{ZonedDateTime}
import play.api.libs.json.{Json, OFormat}
case class Croissant(
id: String,
victimId: String,
creationDate: ZonedDateTime,
doneDate: Option[ZonedDateTime],
scheduleDate: Option[ZonedDateTime],
status: Status,
voters: Seq[String],
email: String,
name: String
) {
def isDone = doneDate.isDefined
}
object Croissant {
implicit val fmt: OFormat[Croissant] = Json.format[Croissant]
}
示例11: Order
//设置package包名称以及导入依赖的类
import play.api.libs.json.{Json, OFormat}
package object models {
case class Order(id: Int = -1,
customerId: Int,
attendees: List[String])
object Order {
implicit val OrderFormat: OFormat[Order] =
Json.format[Order]
}
case class OrderPlaced(order: Order)
object OrderPlaced {
implicit val OrderPlacedFormat: OFormat[OrderPlaced] =
Json.format[OrderPlaced]
}
case class UserRecognized(name: String)
object UserRecognized {
implicit val userRecognizedFormat
: OFormat[UserRecognized] =
Json.format[UserRecognized]
}
}
示例12: SnakeCaseJsonSpec
//设置package包名称以及导入依赖的类
package playjsonsnake
import org.specs2.mutable.Specification
import play.api.libs.json.{ OFormat, Json }
class SnakeCaseJsonSpec extends Specification {
val testCase = TestCase("lowercase", "camelCase", "PascalCase", "camelCaseWithSeveralHumps", "kebab-case")
val testJson = Json parse
"""
|{
| "lowercase": "lowercase",
| "camel_case": "camelCase",
| "Pascal_case": "PascalCase",
| "camel_case_with_several_humps": "camelCaseWithSeveralHumps",
| "kebab-case": "kebab-case"
|}
""".stripMargin
implicit val snakeCaseFormat: OFormat[TestCase] = SnakeCaseJson.format[TestCase]
"SnakeCaseJson format" should {
"convert camel case to snake case when writing Json" in {
val json = Json.toJson(testCase)
json should_=== testJson
}
"convert snake case to camel case when reading Json" in {
val test = testJson.as[TestCase]
test must_=== testCase
}
}
}
case class TestCase(lowercase: String,
camelCase: String,
PascalCase: String,
camelCaseWithSeveralHumps: String,
`kebab-case`: String)
示例13: User
//设置package包名称以及导入依赖的类
package Models
import play.api.libs.json.{Json, OFormat}
import scala.collection.mutable.ListBuffer
case class User (
fname:String,
mname:String,
lname:String,
uname:String,
password:String,
repassword:String,
mobile:String,
gender:String,
age:Int,
hobbies:String
)
object User {
implicit val userJson: OFormat[User] = Json.format[User]
}
示例14: RGB
//设置package包名称以及导入依赖的类
package color
import play.api.libs.json.{Json, OFormat}
final case class RGB(red: Double, green: Double, blue: Double) {
def ^(pow: Double) = RGB(
Math.pow(red, pow),
Math.pow(green, pow),
Math.pow(blue, pow)
)
def awtColor() = new java.awt.Color(
(0f max red.toFloat) min 1f,
(0f max green.toFloat) min 1f,
(0f max blue.toFloat) min 1f
)
def *(s: Double) = RGB(red * s, green * s, blue * s)
def /(s: Double) = RGB(red / s, green / s, blue / s)
def +(c: RGB) = RGB(red + c.red, green + c.green, blue + c.blue)
def -(c: RGB) = RGB(red - c.red, green - c.green, blue - c.blue)
def unary_-() = this * (-1)
def unary_+() = this
def exposureCorrected = RGB(
1 - Math.exp(-red),
1 - Math.exp(-green),
1 - Math.exp(-blue)
)
def gammaCorrected = this ^ (1 / RGB.GAMMA)
}
object RGB {
implicit val colorJsonFormat: OFormat[RGB] = Json.format[RGB]
val BLACK = RGB(0, 0, 0)
val WHITE = RGB(1, 1, 1)
val RED = BLACK.copy(red = 1)
val GREEN = BLACK.copy(green = 1)
val BLUE = BLACK.copy(blue = 1)
val CYAN = BLACK.copy(green = 1, blue = 1)
val YELLOW = RGB(1, 1, 0)
val GAMMA = 2.2
}
示例15: PhilipsSwitch
//设置package包名称以及导入依赖的类
package services.philips_hue
import play.api.libs.json.{Json, OFormat}
import services.common.DomoSwitchBase
case class PhilipsSwitch (
serviceId: Int,
id: String,
status: Boolean,
name: String,
alias: Option[String],
available: Boolean,
color: String
) extends DomoSwitchBase
object PhilipsSwitch {
implicit val domoSwitchFormat: OFormat[PhilipsSwitch] = Json.format[PhilipsSwitch]
}