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 8525949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:07:43+00:00 2026-06-11T08:07:43+00:00

This is my Cout object: case class Cout (idCout:Int, cout:String) object Cout{ implicit object

  • 0

This is my Cout object:

case class Cout (idCout:Int, cout:String)

object Cout{

  implicit object CoutFormat extends Format[Cout] {
    def reads(json: JsValue): Cout = Cout(
      (json \ "idCout").as[Int],
      (json \ "cout").as[String]
    )

    def writes(s: Cout): JsValue = JsObject(Seq(
      "id" -> JsNumber(s.idCout),
      "cout" -> JsString(s.cout)
    ))
  }
}

I’m trying to use this class when calling a webservice using WS:

val cout = response.json.as[Cout]

But the scala compiler keeps complaining:

[RuntimeException: Int expected]

on the line (json \ "idCout").as[Int],

Could anybody tell me what I’m doing wrong?

  • got the example from https://sites.google.com/site/play20zh/scala-developers/working-with-json
  • 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-11T08:07:45+00:00Added an answer on June 11, 2026 at 8:07 am

    You have a typo in your Format instance: you’re writing an "id" field but trying to read one named "idCout". Change one of them:

    case class Cout (idCout: Int, cout: String)
    
    object Cout {
      implicit object CoutFormat extends Format[Cout] {
        def reads(json: JsValue): Cout = Cout(
          (json \ "idCout").as[Int],
          (json \ "cout").as[String]
        )
    
        def writes(s: Cout): JsValue = JsObject(Seq(
          "idCout" -> JsNumber(s.idCout),
          "cout" -> JsString(s.cout)
        ))
      }
    }
    

    And it works:

    scala> Json.toJson(Cout(1, "test")).as[Cout]
    res0: Cout = Cout(1,test)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[a follow up to this question ] class A { public: A() {cout<<A Construction
class test{ public: int data; test(const test& ){cout<<INSIDE COPY CON <<endl;} test(int val =
I have looked at many examples seem to address this simple case. The string
I encountered something that I can't understand. I have this code: cout << f1
Why does this work well: cout << foo; While this doesn't? (&cout)->operator<<(foo); It works
This is a code that uses unique_ptr: struct Foo{ Foo(){std::cout << Ctor called\n;} ~Foo(){std::cout
I have this code in my program: (I included the cout statements for debugging
This is a function in my program. With the cout statement there the program
From this question & the answers - What is the correct answer for cout
For this program #include <iostream> using std::cout; struct C { C() { cout <<

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.