Transformer fails on id fields
Closed this issue · 4 comments
The Id field of each model is of type Long. When converting a search result using the transformer, this numeric value may be returned by ES as an Integer however, causing the ReflectionUtil.setFieldValue(Object, Field, Object) to fail on line 339.
ReflectionUtil should check the actual type of 'value', and should attempt to implicitly convert to the field type (e.g. int -> long).
I will check it out
I've encountered this problem too and have fixed it locally. I need to see how forking and git work to allow all users to get this working.
The actual fix is quite simple:
- I check if the type of value from ES matches the local field type, so we can use field.set() (shortcut for performance)
- Otherwise I use the normal code, with two changes: for both Integers and Longs call field.set() instead of field.setInteger() and field.setLong() because those break
My fix for this has just been integrated
I have just released 0.0.7 with your fixes and also fixes from Alex (@spinscale), author of Play Framework Cookbook. Thank you so much! I am truly touched you cared to commit a fix. By the way do you have a twitter account so I can spread the word?