Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9122083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:00:43+00:00 2026-06-17T06:00:43+00:00

I am a play beginner and try to migrate my web application from Play

  • 0

I am a play beginner and try to migrate my web application from Play 2.0.4 to the new shiny Play 2.1-RC2. My code doesn’t compile because of the new JSON handling.

I have read Mandubians Blog, the Play 2.1 Migration guide and the Play JSON library documentation (beta) but I am still unsure what’s the best way to migrate my code.

F.ex. I have a model called File with an implicit Read-Object (Play 2.0):

object File {
    implicit object FileReads extends Reads[File] {
      def reads(json: JsValue) = File(
        (json \ "name").as[String],
        (json \ "size").as[Long]
     )
   }
}

I use it like this in the controller (Play 2.0):

val file = webserviceResult.json.as[models.File]

The Play 2.1 Migration guide tells me to refactor it with a JsSuccess() like this (Play 2.1?):

object File {
    implicit object FileFormat extends Format[File] {
      def reads(json: JsValue) = JsSuccess(File(
        (json \ "name").as[String],
        (json \ "size").as[Long]
     ))
   }
}

But how can I use this implicit conversion now?

Or is it better to use the implicit val-stuff like in the Twitter-example from the Play for Scala-book? Whats the best way to convert a JsValue to it’s Scala value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:00:44+00:00Added an answer on June 17, 2026 at 6:00 am

    Or is it better to use the implicit val-stuff like in the Twitter-example from the Play for Scala-book?

    Yes, for a classic conversion, it’s a good solution (simple and concise).

    But there is a simpler way to achieve this conversion with the “Json Macro Inception” :

    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    
    case class File(name: String, size: Long)
    implicit val fileFormat = Json.format[File]
    
    val json = Json.parse("""{"name":"myfile.avi", "size":12345}""") // Your WS result
    
    scala> json.as[File]
    res2: File = File(myfile.avi,12345)
    

    Warning: You cannot put your formater in the companion object, it’s a limitation of the current Json API.

    I advice to use an object with all you json formatters, and to import it when necessary.

    FYI, the raw formater should be written like this:

    implicit val rawFileRead: Format[File] = ( 
        (__ \ "name").format[String] and 
        (__ \ "size").format[Long]
    )(File.apply _, unlift(File.unapply _)) // or (File, unlift(File.unapply))
    

    Check these two test class, there are many interesting exemples:

    • JsonSpec
    • JsonExtensionSpec
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, i wrote this pice of code as an beginner in java learning from
testing Play framework and JPA. I eclipsify my very simple test application. Import the
Does play automatically cache data? I'm trying to read this code that someone else
I'm a beginner, I play with FindFirstFileW() of the winapi - C. The unicoded
I'm a beginner in Android development. I'm creating an application where I need to
In my Play 2.0 application I have the following match expression: @item.level match {
I'm just a beginner.. How to play a video or audio using the anchor
im a new beginner in android... i dont know how can i playing audio
Play will assign the parameters from request to action parameters, like: public static void
I play mp3/wav from file to create a push effect. However on an Atom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.