Closed aminelaadhari closed 8 years ago
Indeed there is! You can write a code generation plugin for custom data types as described on this wiki page.
Thanks @sbosley, I will try to create one for Joda DateTime and post back its github reposiotry link here.
I followed the wiki page to create a plugin which converts joda DateTime fields: https://github.com/aminelaadhari/squidb-datetime
@DateTimeColumn DateTime createdAt;
and the result is:
public DateTime getCreatedAt() {
Long instant = this.get(CREATED_AT);
return instant == null ? null : new DateTime(instant);
}
public Habit setCreatedAt(DateTime createdAt) {
this.set(CREATED_AT, createdAt == null ? null : createdAt.getMillis());
return this;
}
One question though, do you think it's better to have the annotation @DateTimeColumn, or I can remove it ?
I ended by removing the annotation because I think a type check is sufficient.
Looks great! I think you're right that in this case the type check is sufficient. Is it ok with you if we add a link to your repo to the wiki so that other users who might be interested can use your plugin?
Yes, sure !
👍 awesome! Going to assume that this issue can be closed then; glad this worked for you!
Is this supported ? I want to use JodaTime DateTime or other types using custom type adapters.
For now I am using ModelMethods as a workaround but it's a lot of boilerplate code:
Is there a better way to implement this ?