equals on two scalaxb identical object fails because DataRecord #120

Closed
deanhiller opened this Issue Nov 18, 2011 · 4 comments

Comments

Projects
None yet
2 participants
@deanhiller

I have two for all intensive purposes equal scalaxb objects BUT they both have a DataRecord and both DataRecords have a different writer field instance and the writer field instance is some anonymous class....can't tell what it was but it seems to have no equals method so object identity is used which fails. I have a huge heirarchy and had to diggggg like so to find out write field in the DataRecord is making my equals assertion fail....

My digging to find the issue(I believe you can simply marshal, unmarshal and compare with Assert.assertEquals(oldObj, newObj) to see the issue BUT you have to have a DataRecord in use to see the issue.....

Assert.assertEquals(evtDoc.EPCISHeader, docFromServer.EPCISHeader)
Assert.assertEquals(evtDoc.any, docFromServer.any)
Assert.assertEquals(evtDoc.attributes, docFromServer.attributes)
Assert.assertEquals(evtDoc.creationDate, docFromServer.creationDate)

Assert.assertEquals(evtDoc.EPCISBody.any, docFromServer.EPCISBody.any)
Assert.assertEquals(evtDoc.EPCISBody.attributes, docFromServer.EPCISBody.attributes)

Assert.assertEquals(evtDoc.EPCISBody.EventList.size, docFromServer.EPCISBody.EventList.size)
val old = evtDoc.EPCISBody.EventList.head
val newOne = docFromServer.EPCISBody.EventList.head
val dr1 :DataRecord[Any] = old.eventlisttypeoption.head
val dr2 :DataRecord[Any] = newOne.eventlisttypeoption.head

val evt1 = dr1.as[ObjectEventType]
val evt2 = dr2.as[ObjectEventType]

Assert.assertEquals(evt1, evt2)

Assert.assertEquals(dr1.key, dr2.key)
Assert.assertEquals(dr1.namespace, dr2.namespace)
Assert.assertEquals(dr1.value, dr2.value)
Assert.assertEquals(dr1, dr2)
Assert.assertEquals(old.eventlisttypeoption, newOne.eventlisttypeoption)

Assert.assertEquals(old, newOne)
Assert.assertEquals(evtDoc.EPCISBody.EventList.head, docFromServer.EPCISBody.EventList.head)

Assert.assertEquals(evtDoc.EPCISBody.EventList, docFromServer.EPCISBody.EventList)
Assert.assertEquals(evtDoc.EPCISBody.extension, docFromServer.EPCISBody.extension)

Assert.assertEquals(evtDoc.EPCISBody, docFromServer.EPCISBody)

Assert.assertEquals(evtDoc.extension, docFromServer.extension)
Assert.assertEquals(evtDoc.schemaVersion, docFromServer.schemaVersion)
@deanhiller

This comment has been minimized.

Show comment
Hide comment
@deanhiller

deanhiller Nov 18, 2011

hmmmm, here is a snapshot of being in debug mode of the two data records and you can see the writer differences...

dr1 = {scalaxb.DataRecord$DataWriter@1762}"DataRecord(ObjectEvent,ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:...
namespace = {scala.None$@2433}"None"
key = {scala.Some@2434}"Some(ObjectEvent)"
xstypeNamespace = {scala.None$@2433}"None"
xstypeName = {scala.None$@2433}"None"
value = {com.ghx.tnt.biz.schema.epcis.ObjectEventType@1755}"ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:disp:in_transit),Some(R...
writer = {com.ghx.tnt.biz.schema.XMLProtocol$$anon$45@2435}
$outer = {com.ghx.tnt.biz.schema.package$@2455}
targetNamespace = {scala.Some@2456}"Some(urn:epcglobal:epcis:xsd:1)"
lastNoSuccess = null
Success$module = null
NoSuccess$module = null
Failure$module = null
Error$module = null
$tilde$module = null


dr2 = {scalaxb.DataRecord$DataWriter@1763}"DataRecord(ObjectEvent,ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:...
namespace = {scala.None$@2433}"None"
key = {scala.Some@2441}"Some(ObjectEvent)"
xstypeNamespace = {scala.None$@2433}"None"
xstypeName = {scala.None$@2433}"None"
value = {com.ghx.tnt.biz.schema.epcis.ObjectEventType@1764}"ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:disp:in_transit),Some(R...
writer = {com.ghx.tnt.biz.schema.XMLProtocol$$anon$45@2442}
$outer = {com.ghx.tnt.biz1.dao.EventDocumentDao$@2447}
targetNamespace = {scala.Some@2448}"Some(urn:epcglobal:epcis:xsd:1)"
lastNoSuccess = {scala.util.parsing.combinator.Parsers$Failure@2449}"[1.10] failure: any expected\n\neventTimeeventTimeZoneOffsetepcListactionbizStepdispositionreadPointbizLocationbizTransactionList\n         ^"
Success$module = null
NoSuccess$module = null
Failure$module = null
Error$module = null
$tilde$module = null

hmmmm, here is a snapshot of being in debug mode of the two data records and you can see the writer differences...

dr1 = {scalaxb.DataRecord$DataWriter@1762}"DataRecord(ObjectEvent,ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:...
namespace = {scala.None$@2433}"None"
key = {scala.Some@2434}"Some(ObjectEvent)"
xstypeNamespace = {scala.None$@2433}"None"
xstypeName = {scala.None$@2433}"None"
value = {com.ghx.tnt.biz.schema.epcis.ObjectEventType@1755}"ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:disp:in_transit),Some(R...
writer = {com.ghx.tnt.biz.schema.XMLProtocol$$anon$45@2435}
$outer = {com.ghx.tnt.biz.schema.package$@2455}
targetNamespace = {scala.Some@2456}"Some(urn:epcglobal:epcis:xsd:1)"
lastNoSuccess = null
Success$module = null
NoSuccess$module = null
Failure$module = null
Error$module = null
$tilde$module = null


dr2 = {scalaxb.DataRecord$DataWriter@1763}"DataRecord(ObjectEvent,ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:...
namespace = {scala.None$@2433}"None"
key = {scala.Some@2441}"Some(ObjectEvent)"
xstypeNamespace = {scala.None$@2433}"None"
xstypeName = {scala.None$@2433}"None"
value = {com.ghx.tnt.biz.schema.epcis.ObjectEventType@1764}"ObjectEventType(2011-11-18T10:39:29.909-07:00,None,,None,EPCListType(List(EPC(urn:epc:id:sgtin:0111222.999888.434), EPC(urn:epc:id:sgtin:0111222.999888.827))),OBSERVE,Some(urn:epcglobal:cbv:bizstep:shipping),Some(urn:epcglobal:cbv:disp:in_transit),Some(R...
writer = {com.ghx.tnt.biz.schema.XMLProtocol$$anon$45@2442}
$outer = {com.ghx.tnt.biz1.dao.EventDocumentDao$@2447}
targetNamespace = {scala.Some@2448}"Some(urn:epcglobal:epcis:xsd:1)"
lastNoSuccess = {scala.util.parsing.combinator.Parsers$Failure@2449}"[1.10] failure: any expected\n\neventTimeeventTimeZoneOffsetepcListactionbizStepdispositionreadPointbizLocationbizTransactionList\n         ^"
Success$module = null
NoSuccess$module = null
Failure$module = null
Error$module = null
$tilde$module = null
@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Nov 18, 2011

Owner

Yea, DataRecord should ignore writer.

Owner

eed3si9n commented Nov 18, 2011

Yea, DataRecord should ignore writer.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Nov 18, 2011

Owner

So I have created a repro test case here:

  def testDataRecordEquality {
    println("testDataRecordEquality")

    val subject = <foo xmlns="http://www.example.com/general"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <person1><firstName>John</firstName><lastName>Doe</lastName></person1>
      <person2 xsi:nil="true"/>
      <person3><firstName>John</firstName><lastName>Doe</lastName></person3>
      <person5><firstName>John</firstName><lastName>Doe</lastName></person5>
        <person5><firstName>John</firstName><lastName>Doe</lastName></person5>
      <person6 xsi:nil="true"/>
    </foo>
    val r1 = scalaxb.fromXML[ChoiceComplexTypeTest](subject)
    val document = toXML(r1, "foo", subject.scope)
    val r2 = scalaxb.fromXML[ChoiceComplexTypeTest](document)

    (r1 == r2) match {
      case true =>
      case _ => error("r1 and r2 are not equal: " + r1.toString + " and " + r2.toString)
    }
  }

I need to pull out my Effective Java 2nd ed to implement equals correctly.

Owner

eed3si9n commented Nov 18, 2011

So I have created a repro test case here:

  def testDataRecordEquality {
    println("testDataRecordEquality")

    val subject = <foo xmlns="http://www.example.com/general"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <person1><firstName>John</firstName><lastName>Doe</lastName></person1>
      <person2 xsi:nil="true"/>
      <person3><firstName>John</firstName><lastName>Doe</lastName></person3>
      <person5><firstName>John</firstName><lastName>Doe</lastName></person5>
        <person5><firstName>John</firstName><lastName>Doe</lastName></person5>
      <person6 xsi:nil="true"/>
    </foo>
    val r1 = scalaxb.fromXML[ChoiceComplexTypeTest](subject)
    val document = toXML(r1, "foo", subject.scope)
    val r2 = scalaxb.fromXML[ChoiceComplexTypeTest](document)

    (r1 == r2) match {
      case true =>
      case _ => error("r1 and r2 are not equal: " + r1.toString + " and " + r2.toString)
    }
  }

I need to pull out my Effective Java 2nd ed to implement equals correctly.

@eed3si9n eed3si9n closed this in 6482e5b Nov 18, 2011

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Nov 18, 2011

Owner

0.6.7-SNAPSHOT is out with the fix.

Owner

eed3si9n commented Nov 18, 2011

0.6.7-SNAPSHOT is out with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment