-
Notifications
You must be signed in to change notification settings - Fork 822
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
Fix for CompatibleFieldSerializer inheritance issue #424
Conversation
Intersting approach, great idea! Suggestions:
@NathanSweet WDYT? |
I did some changes:
|
I wonder if it makes any sense for |
There are some methods in
... all this methods would need to be overriden in ... but I got your point. I don't like to attack the |
Hi @magro, would like to go ahead with this PR, but I'm confused somehow. The getField(String) and removeField(String) in FieldSerializer can't work correctly with the current/default approach. They get/remove only the first field with same name... but if there are more fields with same name (but different class), they give wrong result. I can do now the fix only for CompatibleFieldSerializer...but need then override the getField/removeField methods.... To fix it in FieldSerializer already seems to be much better for me. WDYT? |
Sounds reasonable to fix FieldSerializer, can you do this in a separate commit or even separate PR? Adding a test for this as well would be super awesome :-) |
Hi @magro, the new PR would have identical commits like this one ;) If you think it's neccessary, I'll do it. But pls. explain me how it should help us? I'll try to sum up the new features/bugfixes that are comming with this PR:
|
A PR with a bugfix and a test usually can be merged fairly fast. Therefore I mentioned this option. You can also add the commit to this PR. Please add a test that shows the issue for FieldSerializer as well. Thanks! |
@xfrendx We're going to have a release soon, what do you think when you can finalize this? |
Hi @magro, I added the TCs right now, pls. check it. Thx |
@@ -621,7 +621,71 @@ public void testMultipleTimesAnnotatedMapFields () { | |||
|
|||
assertFalse("Exception was expected", true); | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind you could put this into a FieldSerializerInheritanceTest
- sorry that I've suggested to add this to this test, I wasn't aware that it's already that big...
@xfrendx Thanks, I added minor/cosmetic comments. Once they're resolved please squash the changes to a single commit and change the commit message to mention both FieldSerializer and CompatibleFieldSerializer. I'll then merge the PR. |
@magro your suggestions have been added and changes suqashed to one commit. Let me know if there is something left... |
@@ -0,0 +1,129 @@ | |||
package com.esotericsoftware.kryo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the license header.
@xfrendx Great, thanks! In the new test only the license header is missing. Please change the commit message to s.th. like "Support 'duplicate'/overwritten fields in (Compatible)FieldSerializer" and add a description with the what and why of the change. This would be perfect :-) |
…e how CachedFields are recognized in FieldSerieliazer and CompatibleFieldSerializer. It is an improvement for FieldSerializer (influences getField/removeField methods) and nearly a must have in CompatibleFieldSerialzer in case your class hierarchy contains same named fields (e.g. class A has a field named "a", and class B extends A and also contains a field named "a"). Per default, both mentioned serializers behave like before (DEFAULT strategy used). To change it, use `kryo.getFieldSerializerConfig().setCachedFieldNameStrategy(FieldSerializer.CachedFieldNameStrategy.EXTENDED);`. At this moment, class simple name is added to CachedField name. This helps in CompatibleFieldSerializer write the right value to right class field. Without EXTENDED, all same named values are written just to the first found field.
@magro done |
@xfrendx Following general rules on commit messages they should have a short title/subject identifying the change. The description should be separated from the title with an empty line. See also http://chris.beams.io/posts/git-commit/ |
Added an option/strategy to influence how CachedFields are recognized in FieldSerieliazer and CompatibleFieldSerializer. It is an improvement for FieldSerializer (influences getField/removeField methods) and nearly a must have in CompatibleFieldSerialzer in case your class hierarchy contains same named fields (e.g. class A has a field named "a", and class B extends A and also contains a field named "a"). Per default, both mentioned serializers behave like before (DEFAULT strategy used). To change it, use `kryo.getFieldSerializerConfig().setCachedFieldNameStrategy(FieldSerializer.CachedFieldNameStrategy.EXTENDED);`. At this moment, class simple name is added to CachedField name. This helps in CompatibleFieldSerializer write the right value to right class field. Without EXTENDED, all same named values are written just to the first found field. Resolves: EsotericSoftware#424 See also: EsotericSoftware#187
@magro thx for you patience & done |
Added an option/strategy to influence how CachedFields are recognized in FieldSerieliazer and CompatibleFieldSerializer. It is an improvement for FieldSerializer (influences getField/removeField methods) and nearly a must have in CompatibleFieldSerialzer in case your class hierarchy contains same named fields (e.g. class A has a field named "a", and class B extends A and also contains a field named "a"). Per default, both mentioned serializers behave like before (DEFAULT strategy used). To change it, use `kryo.getFieldSerializerConfig().setCachedFieldNameStrategy(FieldSerializer.CachedFieldNameStrategy.EXTENDED);`. At this moment, class simple name is added to CachedField name. This helps in CompatibleFieldSerializer write the right value to right class field. Without EXTENDED, all same named values are written just to the first found field. Resolves: EsotericSoftware#424 See also: EsotericSoftware#187
Added an option/strategy to influence how CachedFields are recognized in FieldSerieliazer and CompatibleFieldSerializer. It is an improvement for FieldSerializer (influences getField/removeField methods) and nearly a must have in CompatibleFieldSerialzer in case your class hierarchy contains same named fields (e.g. class A has a field named "a", and class B extends A and also contains a field named "a"). Per default, both mentioned serializers behave like before (DEFAULT strategy used). To change it, use `kryo.getFieldSerializerConfig().setCachedFieldNameStrategy( FieldSerializer.CachedFieldNameStrategy.EXTENDED);`. At this moment, class simple name is added to CachedField name. This helps in CompatibleFieldSerializer write the right value to right class field. Without EXTENDED, all same named values are written just to the first found field. Resolves: EsotericSoftware#424 See also: EsotericSoftware#187
@xfrendx Awesome, thanks! :-) |
My try to fix the PR #187. This solution here doesn't ignore "duplicate" fields, because they are not duplicate at all. They just belongs to different classes...
Added a central method FieldSerializer#getFieldName(CachedField) that returns per default the field name. This behaviour is overriden in CompatibleFieldSerialzer and can be driven by the "extendedFieldNaming" boolean. If extendedFieldNaming is true, then Class simple name is added to the field name... and this helps to find the right field when deserializing. It's not perfect, but don't want to have it too verbose.
Any suggestions will be welcome!