Let's start with use-cases.
Use-case 1. Paul opens an online shop with solder irons (very specialist shop), to sell to the public. Each iron has a name and a price. Prices are in any currency.
public interface SolderIron extends EntityComposite
{
Property<String> name();
Property<Money> price();
}
public void addSolderIron( String name, BigDecimal amount, CurrencyUnit currency )
{
Money price = Money.of( currency, amount );
UnitOfWork uow = module.currentUnitOfWork();
EntityBuilder<Product> builder = uow.newEntityBuilder( SolderIron.class );
SolderIron instance = builder.instance();
instance.price().set( price );
builder.newInstance();
}
Use-case 2. Niclas wants to buy a soldering iron that cost less than USD200. Irons sold in another currency should not be considered.
Money maxPrice = Money.of( CurrencyUnit.USD, 200 );
QueryBuilder<SolderIron> qb = module.newQueryBuilder(SolderIron.class);
SolderIron s = templateFor( SolderIron.class );
qb = qb.where( lt( s.price(), maxPrice) );
Query<SolderIron> query = qb.newQuery
Use-case 3. Niclas wants to buy a soldering iron that cost less than USD200 or equivalent in other currency.
This is the really tricky bit, and will only work with some form of Currency Conversion, which is not part of Joda-time's scope. So, perhaps that is part of Qi4j's Money support, and Conversion service (the impl is not part of it).
Money maxPrice = Money.of( CurrencyUnit.USD, 200 );
Iterable<Money> converted = conversionService.convertAll( maxPrice );
QueryBuilder<SolderIron> qb = module.newQueryBuilder(SolderIron.class);
SolderIron s = templateFor( SolderIron.class );
for( Money price : converted )
qb = qb.where( lt( s.price(), maxPrice) );
Query<SolderIron> query = qb.newQuery
(I can't recall if successive where() results in a logical-OR... perhaps it is AND).
-o-o-o-
None of this depends on the underlying storage format of the indexer, nor the storage in the entity store.
For ValueSerialization, I think the { "currency": "USD", "amount": 188.88 } is good.
For indexing, it depends on the underlying store, a case-by-case. In SQL, I could imagine that a new table is needed for money entries which has EntityID, PropertyName, Amount, Currency columns.
I am not sure why you think that "object" is not possible in ValueSerialization. The type information is coming from the Java side anyway, and we have (I think) ability to put (de)serializer per type.
Niclas