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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:40:03+00:00 2026-06-13T20:40:03+00:00

This part of my application parses to and from a JSON into my objects.

  • 0

This part of my application parses to and from a JSON into my objects. I created a unit test that creates a ‘PurchaseOrder’, transforms it into JSON and transforms it back into the same type of object, and uses reflection to check both the original and the final PurchaseOrder are identical:

val purchaseOrderJson = PurchaseOrderJson.toJson(purchaseOrder)
val clientPurchaseOrder = PurchaseOrderJson.fromJson(purchaseOrderJson)

val reflectionCheck = classOf[PurchaseOrder].getMethods.forall {
 (method: Method) =>
    if (!method.invoke(purchaseOrder).equals(method.invoke(clientPurchaseOrder))) {
      println("%s unequal: %s vs %s".format(method.getName, method.invoke(purchaseOrder), method.invoke(clientPurchaseOrder)))
      false
    } else {
      true
    }
}

This is the JSON:

"purchaseOrders": [{
    "id": "522423",
    "lineItems": [{
        "notes": "Important item",
        "origin": "Spain"
      },{
        "notes":null,
        "origin": "Italy"
    }]
}]

I have the objects defined as traits:

trait PurchaseOrder {
  def id: String
  def lineItems: Vector[LineItem]
}

trait LineItem {
  def notes: Option[String]
  def origin: String
}

And the implementations as follows:

class PurchaseOrderJson(
    @(JsonProperty @field) override val id: String,
    @(JsonProperty @field) override val lineItems: Vector[LineItemImpl]
) extends PurchaseOrder {
    def this() = this("",Vector.empty[LineItemImpl])
}

case class LineItemImpl(notes: Option[String]) extends LineItem

Now 🙂 my problem is I have to add a LOT of fields to LineItem and the compiler complains that I can’t have more than 22 params in a case class. So what I did is rewrite LineItemImpl to look like this:

class LineItemImpl(
    @(JsonProperty @field) override val notes: Option[String] = None
) extends LineItem {
    def this() = this(None)
}

But now I get an error in my reflection unit test:

lineItems unequal: Vector(com.giltgroupe.purchaseorder.core.json.LineItemImpl@5b6ca395) vs Vector(com.giltgroupe.purchaseorder.core.json.LineItemImpl@3967ba17)

That means the two Vectors in the two objects being compared differ in the element inside. I understand this is because when I change the case class to standard class it looses some pattern match properties so now it’s comparing the object address instead of the content.

Is there any way to fix this adding some more properties or annotations to LineItemImpl? Or the only thing I can do is modify my reflection check to drill down into the Vectors? Ideally I don’t want to modify the unit test.

Thanks!

  • 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-13T20:40:06+00:00Added an answer on June 13, 2026 at 8:40 pm

    I found out that I was missing a method that is created automatically for case classes, equals

     override final def equals (other:Any):Boolean = {}
    

    In this case I also need to define the hashCode method, not necessary for my code to run but it might give weird behavior down the road if not included:

    override final def hashCode(): Int = ScalaRunTime.this._hashCode(LineItemJson.this)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do an Application test that parses some json, stores to core
I want to split the json part from this URL in my iPhone application.
I have this part of script from my GAE application which uses webapp2, which
I have a regular .NET application. In this case I have a part that's
We have a test WCF client hooked up to our application that parses xml
I am working on an application that works like this: It fetches data from
I want to code this part of a VB6 application in c#. How can
You may skip this part: I am creating an application where the client needs
I'm trying to setup the application server part of C2DM push messaging using this
As part of my ecommerce application, I have this interesting problem, I've been trying

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.