playframework-2.0

Applying conversion to play framework json element before applying to class

我与影子孤独终老i 提交于 2020-01-07 01:48:31
问题 I have a class as so case class Token( creationDate: Date, expires: Option[Date] ) { def toJson(): String = Json.stringify(Json.toJson(this)) } object Token { def fromJson(json: String): Token = Json.parse(json).as[Token] implicit val tokenReads: Reads[Token] = ( (JsPath \ "creation_date").read[Date] and (JsPath \ "expires").readNullable[Date] ) (Token.apply _) implicit val tokenWrites: Writes[Token] = ( (JsPath \ "creation_date").write[Date] and (JsPath \ "expires").writeNullable[Date] )

Parse Simple Json Array in Play Framework

﹥>﹥吖頭↗ 提交于 2020-01-06 14:01:15
问题 I'm sure there is a simple way to do this, but I haven't found a way to do it. How do I go about parsing a simple json array: [1] as a List[Integer] or List[String] with the play framework Json Library in scala? All of the examples I have seen in the documentation assume you are working with an object and are accessing an attribute in the object. When I try to parse the json I get an error: jsonResult.as[List[String]] JsError(List((,List(ValidationError(error.expected.jsarray,WrappedArray()))

Parse Simple Json Array in Play Framework

不问归期 提交于 2020-01-06 13:59:30
问题 I'm sure there is a simple way to do this, but I haven't found a way to do it. How do I go about parsing a simple json array: [1] as a List[Integer] or List[String] with the play framework Json Library in scala? All of the examples I have seen in the documentation assume you are working with an object and are accessing an attribute in the object. When I try to parse the json I get an error: jsonResult.as[List[String]] JsError(List((,List(ValidationError(error.expected.jsarray,WrappedArray()))

Cloud Foundry Playframework : Error 310: Staging failed:

痞子三分冷 提交于 2020-01-06 07:25:20
问题 I am trying to host a sample (HelloWorld) Play app in Cloud Foundry but am always getting this error at Staging, Error 310: Staging failed: 'Staging task failed: Staging plugin failed: cp: cannot stat `/var/vcap/data/stager/tmp/d20120828-24156-128z05h/unstaged/logs/*': No such file or directory /var/vcap/data/packages/ruby/6.1/lib/ruby/1.9.1/fileutils.rb:1231:in `chmod': No such file or directory - /var/vcap/data/stager/tmp/d20120828-24156-128z05h/staged/app/start (Errno::ENOENT) from /var

Add optional property with json transformers in playframework 2.4

梦想的初衷 提交于 2020-01-06 02:24:08
问题 I can't understand, how can i add optional property with json transformer. I want merge two json objects (list and calendars) without or with dynamic list of properties (for example without owner ): calendar1 = {id:1, name: "first", description:"my first calendar", owner: 1} calendar2 = {id:2, name: "second", owner: 1} list = [{id: 1, settings: []}, {id: 2, settings: []}] and result must be {calendars: [ {id:1, name: "first", description:"my first calendar", settings: []}, {id:2, name:

How to put a JAR file in a Play 2 project and use it?

拈花ヽ惹草 提交于 2020-01-05 14:52:05
问题 In Play 1, we can put some JAR files into the /lib directory. But there is no such a directory, and I don't find any information to do this. Play 2 uses repositories, but sometimes I just want a quick and dirty way to use a JAR file. How do I do that? 回答1: Since Play 2 applications are built using sbt, you can just follow their convention for unmanaged dependencies: put your JAR file in the lib/ directory. 来源: https://stackoverflow.com/questions/9287880/how-to-put-a-jar-file-in-a-play-2

Play framework 2: Passing java objects between controllers

一笑奈何 提交于 2020-01-05 10:35:32
问题 I have a java User object which i want to pass from my Login controller to my Dashboard controller. ive read a bunch and im trying the following implementation public static Result authenticate(){ Form<LoginForm> loginform = Form.form(LoginForm.class).bindFromRequest(); if(loginform.hasErrors()){ return badRequest(login.render(loginform)); } else{ session().clear(); AppUser user = AppUser.getUserByEmail(loginform.get().email); Context.current().args.put("user", user); return redirect(routes

Play framework 2: Passing java objects between controllers

巧了我就是萌 提交于 2020-01-05 10:34:46
问题 I have a java User object which i want to pass from my Login controller to my Dashboard controller. ive read a bunch and im trying the following implementation public static Result authenticate(){ Form<LoginForm> loginform = Form.form(LoginForm.class).bindFromRequest(); if(loginform.hasErrors()){ return badRequest(login.render(loginform)); } else{ session().clear(); AppUser user = AppUser.getUserByEmail(loginform.get().email); Context.current().args.put("user", user); return redirect(routes

Play framework JSON list binding

房东的猫 提交于 2020-01-05 10:13:14
问题 I am new into Play, and I want to try to bind a List of String from a JSON post. I do the following: import play.data.validation.Constraints; import java.util.ArrayList; import java.util.List; Form<Person> PERSON = new Form<>(Person.class); Form<Person> filledForm = PERSON.bind(request().body().asJson()); Person class { @Constraints.Required @Constraints.Email private String email; @Constraints.Required private List<String> adresses = new ArrayList<>(); } I get the following message: "matches

Play framework, inserting initial-data more than 20 items per one Model

廉价感情. 提交于 2020-01-05 10:08:04
问题 In the development mode of Play framework, I inserted my initial-data.yml through Global.java. However, if one model has more than 20 items, autu-generated IDs is going crazy. For example, if I had: computers: - !!models.Computer name: apple01 - !!models.Computer name: apple02 - !!models.Computer name: apple03 - !!models.Computer name: apple04 ... - !!models.Computer name: apple20 - !!models.Computer name: apple21 - !!models.Computer name: apple22 From 1 to 20, they got correct auto-generated