Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Serialization (CompatibleFieldSerializer) #556

Closed
oassuncao opened this issue Dec 1, 2017 · 12 comments
Closed

Wrong Serialization (CompatibleFieldSerializer) #556

oassuncao opened this issue Dec 1, 2017 · 12 comments

Comments

@oassuncao
Copy link

oassuncao commented Dec 1, 2017

I use kryo to serialize information between my systems, but I've some problems when some fields not exists in the class when I read the values. I created a project to simulate the problem (kryotest.zip)

I created a class named DefaultClassResolver only to change the Class Types and simulate other system and other classes with the same structure

I have the original classes in the package kryo.test.SupplierInitial and the classes of other system in the package kryo.test.SupplierWrapper

If run the app without any change the output is "Wrong", because the nature field receive the value of the link field, this occurs because the class SupplierAggregationME in the package kryo.test.SupplierInitial has 2 fields (value and total) and in the class SupplierAggregationME of package kryo.test.SupplierWrapper have only one field total.

If you uncomment the field value, getter and setter of class kryo.test.SupplierWrapper.SupplierAggregationME, the problem doesn't occur, The output is "Correct"

This is only an example, if you comment all fields (getter and setter) of the SupplierME classes (SupplierInitial and SupplierWrapper packages) you can verify the nature field receive the value of name field

kryotest.zip

@oassuncao
Copy link
Author

oassuncao commented Jan 4, 2018

Anybody has any information about this bug? @NathanSweet

This problem occurs in production

@oassuncao
Copy link
Author

Hey guys

Someone can you help me?

@magro
Copy link
Collaborator

magro commented Mar 20, 2018

@oassuncao It would help if you could further reduce the sample, following the ideas of http://www.sscce.org.

@oassuncao
Copy link
Author

oassuncao commented Mar 20, 2018

@magro This is a reduced example of the original code, I could only reproduce this error with this composition classes and values

If I remove a field of the POJO, the error does not occurs more

Please try to help me, I have this problem in the production environment

@magro
Copy link
Collaborator

magro commented Mar 20, 2018

Can you remove as many as classes as possible to see where/when the error starts to occur?

@oassuncao
Copy link
Author

I removed all classes as possible, If I remove any other class, the error does not occur

kryotest_slim.zip

@magro
Copy link
Collaborator

magro commented Mar 23, 2018

Ok, I analyzed this and could track it down to the NatureType. If you change DocumentType.type from NatureType to String it works. I also removed the differences between the two NatureTypes, unfortunately this did not solve it. That's everything I could find so far, I'll see if I can dig deeper.

@oassuncao
Copy link
Author

Thank you @magro for you support

Check if you remove the "aggregations" data on data.json, the problem not occur more

{
  "suppliers": [
    {
      "nature": "LegalEntity",
      "documents": [
        {
          "value": "42216103000133",
          "type": {
            "type": "LegalEntity"
          }
        }
      ]
    }
  ]
}

@magro
Copy link
Collaborator

magro commented Mar 23, 2018

Yes, it's caused by the LegalEntity which occurs twice. There seems to be an issue with the reference handling - i.e. if you add kryo.setReferences(false); it works!

@magro
Copy link
Collaborator

magro commented Mar 25, 2018

More findings: because the SupplierAggregationME.value field (with value "Brazil") is missing on read side its object reference is not read and not added to Kryo.readReferenceIds, so that in consequence the following reference ids are off by one. Because during write the second LegalEntity was stored as object reference to the first one, the object registered for the reference id is used - which is then 42216103000133 instead of LegalEntity (off by one).

@magro
Copy link
Collaborator

magro commented Mar 25, 2018

@oassuncao D'oh, after all that digging I just found that this issue had actually been analyzed and discussed in the past - see #286 (comment). And in fact it's also documented in CompatibleFieldSerializer and the README.

If you follow the discussion and links you'll see that this is not easily being solved. Can you for now disable referenced to get this solved? Not sure if / when there's a solution for this.

@oassuncao
Copy link
Author

Hi @magro, If I disable the references, the problem is resolved

I will try use this solution for now

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

No branches or pull requests

2 participants