[JAVA-2709] Pojo with method returning an Enum - NPE / "Can't find a codec for class" Created: 15/Dec/17 Updated: 20/Dec/17 Resolved: 19/Dec/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | POJO |
| Affects Version/s: | 3.6.0 |
| Fix Version/s: | 3.6.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | aneta stępień | Assignee: | Ross Lawley |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Using Enums with the PojoCodecProvider.Builder.automatic(true) causes a NPE. Was Hi again,
I get NullPointerException in PojoCodecImpl:shouldSpecialize (:332) If I change the name of the metod (so that it is not mistaken with a getter):
I get a If I remove this method from my pojo, everything works fine. |
| Comments |
| Comment by Githook User [ 20/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com', 'username': 'rozza'}Message: Fix PojoCodec NPE with automatic mapping of Enums
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 19/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Ross Lawley', 'email': 'ross.lawley@gmail.com', 'username': 'rozza'}Message: Fix PojoCodec NPE with automatic mapping of Enums
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 15/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks jcodagnone it seems the automatic(true) flag tries to make a ClassModel for the Enum. We'll look to fix for 3.6.1 Ross | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Juan F. Codagnone [ 15/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, I'm getting the (same?) NPE when activating the automatic creation of ClassModel. At some point during the construction of PojoCodeImpl of the enum during the specialize() it goes fishing for declaringClass as a bean property (which is not). I was able to reproduce on PojoCustomTest on 2aed4786df048ba5545cf3976c5a29e19f5db66f (Thu Dec 14 12:16:23 2017 +0000) PropertyModel{propertyName='declaringClass', readName='declaringClass', writeName='declaringClass', typeData=TypeData{type=Class, typeParameters=[SimpleEnum] }}
Edit Added the stacktrace:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 15/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Aneta Stępień, I'm still unable to reproduce the error on the 3.6.0 version of the driver. In fact the code above works as expected and if I set a default simpleEnum value, then the property myEnum is encoded but the field simpleEnum is ignored - as per the annotation. Looks like there is something else missing, that is causing the error. Could you output the full stacktrace? Perhaps that will throw some light on the issue. Ross | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by aneta stępień [ 15/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you for quick response! You are right, your code works. I checked the differences and found the one that matters - the enum exists in the abstract class, which my pojo extends. Here is a simplified code that results in the same error:
One note - in the real example there si no field with this enum - only a method that calculates it:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 15/Dec/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Aneta Stępień, Thanks for the ticket, sorry to hear you're having an issue. Can I confirm this is with the 3.6.0 version of the java driver? I was able to encode and decode the following POJO:
It created a Document in the shape of: {myInteger: 1}. If you could provide more information on the POJO, so that I can reproduce the error that would be great. Ross |