mattinsler/com.lowereast.guiceymongo

Autoconversion int32 -> int64

Opened this issue · 1 comments

Generated code should support numeric type autoconversion. What I find frustrating is that I started modeling some fields with int32. However when I changed document model from int32 to int64, the generated java code fails on typecast conversion from java.lang.Integer to java.lang.Long. Is there a way to generate java code with up-type conversion?

That's acutally necessary in a few areas that I've been finding as well. I don't like the idea of having all that if typeof code in the default generated code. However, I think it'd be good to add an option that can insert that code into the accessors. This way, the conversions can be optional for those cases where you can't control the types in the db.

Maybe there could be named conversions, or even just a [convert-from(int32)] or something. The question of whether to write those conversions back into the database could come up as well. I would say not to commit those back, since this is not meant to be a full ORM, but just a functionality wrapper around the data itself.