doanduyhai / Achilles

An advanced Java Object Mapper/Query DSL generator for Cassandra
http://achilles.archinnov.info
Apache License 2.0
241 stars 92 forks source link

Achilles can't deserialize undefined field into primitive #357

Closed ook closed 5 years ago

ook commented 5 years ago

Hi @doanduyhai ,

When you use Achilles to map a cassandra boolean into java primitive, Achilles will raise if the field is undefined.

I'd expect it map to default java primitive value (false for boolean, 0 for integer, etc.) I tried to workaround using a Codec but as stated in #330 undefined cassandra value doesn't trigger the Codec.

doanduyhai commented 5 years ago

"Achilles will raise if the field is undefined." --> What do you mean by undefined ? Null value ?

ook commented 5 years ago

Yes, value never written into Cassandra (as you can do for non key or non clustering fields).

doanduyhai commented 5 years ago

So a very simple work-around:

  1. do not use primitive types for nullable values in Cassandra, use rather object type Boolean
  2. use Optional<Boolean> type in Achilles
ook commented 5 years ago

Thank you for your answer. I guess that could make its way into a FAQ.