My decision:
Define Interface:
public interface RealmConvert { void convertToDB(); void convertToObj(); }
Define the entity:
@Ignore private BigDecimal balance; private String balanceStr;
@Override public void convertToDB() { if (getBalance() != null) { setBalanceStr(getBalance().toString()); } }
@Override public void convertToObj() { if (getBalanceStr() != null) { setBalance(new BigDecimal(getBalanceStr())); } }
Before copying ToRealm: calling the convertToDB method
When you need to use an entity: call the convert obj method
This is not an elegant solution, but it works.
Christian Cupronickel answer does not work in my application.
source share