• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala OFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中play.api.libs.json.OFormat的典型用法代码示例。如果您正苦于以下问题:Scala OFormat类的具体用法?Scala OFormat怎么用?Scala OFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了OFormat类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
  )
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:25,代码来源:MenuPerDayPerPersonForm.scala


示例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]
} 
开发者ID:Saverin-lab,项目名称:katebin-rest,代码行数:30,代码来源:models.scala


示例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)
    }
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:31,代码来源:Task.scala


示例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)
    )
  }
} 
开发者ID:stonexx,项目名称:utils,代码行数:46,代码来源:Cat.scala


示例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]
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:30,代码来源:Dish.scala


示例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)
  )
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:48,代码来源:MenuPerDayForm.scala


示例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)
  )
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:34,代码来源:ProfileForm.scala


示例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)
  )
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:35,代码来源:MenuForm.scala


示例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)
  )
} 
开发者ID:lunatech-labs,项目名称:lunatech-lunch-planner,代码行数:51,代码来源:DishForm.scala


示例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]
} 
开发者ID:denis-mludek,项目名称:zencroissants,代码行数:24,代码来源:Croissant.scala


示例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]
  }

} 
开发者ID:leanovate,项目名称:contoso-conference-manager,代码行数:30,代码来源:package.scala


示例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) 
开发者ID:beamly,项目名称:playjsonsnake,代码行数:40,代码来源:SnakeCaseJsonSpec.scala


示例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]

} 
开发者ID:mahesh2492,项目名称:play_Assignment01,代码行数:23,代码来源:User.scala


示例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

} 
开发者ID:wookenny,项目名称:scalarty,代码行数:50,代码来源:RGB.scala


示例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]
} 
开发者ID:acperez,项目名称:DomoControl-Server,代码行数:19,代码来源:PhilipsSwitch.scala


示例16: serviceId

//设置package包名称以及导入依赖的类
package services.common

import play.api.libs.json.{Json, OFormat}

trait DomoSwitchBase {
  def serviceId: Int
  def id: String
  def status: Boolean
  def name: String
  def alias: Option[String]
  def available: Boolean
}

case class DomoSwitch(
  serviceId: Int,
  id: String,
  status: Boolean,
  name: String,
  alias: Option[String],
  available: Boolean
)  extends DomoSwitchBase

object DomoSwitch {
  implicit val domoSwitchFormat: OFormat[DomoSwitch] = Json.format[DomoSwitch]
} 
开发者ID:acperez,项目名称:DomoControl-Server,代码行数:26,代码来源:DomoSwitch.scala


示例17: CityDao

//设置package包名称以及导入依赖的类
package models.daos

import models.City
import play.api.libs.json.{Json, OFormat}
import reactivemongo.api.commands.WriteResult
import reactivemongo.bson.BSONObjectID
import reactivemongo.play.json._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

object CityDao extends MongoDao {
  override val collectionName: String = "city"

  def find(id: BSONObjectID): Future[Option[City]] = {
    super.findById[City](id)
  }

  def save(model: City): Future[WriteResult] = {
    super.save[City](model)
  }

  def findByName(name: String)(implicit format: OFormat[City]): Future[List[City]] = {
    collection.flatMap(_.find(Json.obj("name" -> name))
      .sort(Json.obj("created" -> -1))
      .cursor[City]()
      .collect[List]()
    )
  }
} 
开发者ID:Hendra-Huang,项目名称:play-scala2-reactivemongo,代码行数:31,代码来源:CityDao.scala


示例18: crudActionBuilder

//设置package包名称以及导入依赖的类
package ch.wavein.play.mongo.components

import ch.wavein.play.mongo.SecureUpdateAction
import ch.wavein.play.mongo.actions.ExistenceFilter
import ch.wavein.play.mongo.model.Identity
import ch.wavein.play.mongo.providers.Provider
import play.api.libs.json.{Json, OFormat}
import play.api.mvc.BodyParsers.parse
import play.api.mvc.{ActionBuilder, Controller, Request}

import scala.concurrent.ExecutionContext


trait CrudActions[T <: Identity] extends Controller {
  def crudActionBuilder: ActionBuilder[Request]

  implicit def crudFormatter: OFormat[T]

  def modelProvider: Provider[T]

  implicit def ec: ExecutionContext


  def list() = crudActionBuilder.async { implicit request =>
    for {
      allSubs <- modelProvider.list()
    } yield Ok(Json.toJson(allSubs))
  }

  def get(id: String) = (crudActionBuilder andThen ExistenceFilter(id, modelProvider)).async { implicit request =>
    for {
      sub <- modelProvider.get(id)
    } yield Ok(Json.toJson(sub))
  }

  def update(id: String) = SecureUpdateAction(id) {
    (crudActionBuilder andThen ExistenceFilter(id, modelProvider)).async(parse.json[T]) { implicit request =>
      val sub = request.body

      for {
        subUpdate <- modelProvider.update(sub)
      } yield Ok(Json.toJson(subUpdate))
    }
  }

  def add() = crudActionBuilder.async(parse.json[T]) { implicit request =>
    val sub = request.body

    for {
      subAdded <- modelProvider.insert(sub)
    } yield Ok(Json.toJson(subAdded))

  }

  def delete(id: String) = (crudActionBuilder andThen ExistenceFilter(id, modelProvider)).async { implicit request =>
    for {
      subDeleted <- modelProvider.delete(id)
    } yield Ok(Json.toJson(subDeleted))
  }
} 
开发者ID:waveinch,项目名称:wi-play-mongo,代码行数:61,代码来源:CrudActions.scala



注:本文中的play.api.libs.json.OFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala anyString类代码示例发布时间:2022-05-23
下一篇:
Scala AhcWSComponents类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap