I am using Nomin for mapping tasks. As taken from the documentation of Nomin it should be able to map fields with the same name by itself in case automapping has been activated. When activating it, it causes an infinite loop exception.
I have the following:
mappingFor a: CoinsOnMarketPlace, b: Coin
// automap() // when deactivated it works fine, when activated infinite loop
a.coin.name = b.name
a.coin.rank = b.rank
a.priceUSD = b.priceUSD // Could be automapped
a.priceBTC = b.priceBTC // Could be automapped
...
Exception:
org.nomin.core.NominException: ./net/hemisoft/ccm/repository/coinmarketcap2coin.groovy: Recursive mapping rule a = b causes infinite loop!
One thing worth adding regarding your use case - this
Recursive mapping rule a = b causes infinite loop!exception is thrown because you use groovy classes in your mapping rule. Nomin usesReflectionIntrospectorand what's important:A simple Groovy class like:
gets compiled to a Java class that implements
GroovyObjectproviding following methods:In this case
ReflectionInstanceCreatorcombined withautomap()resolves following mappings:and
where
a = bmapping comes fromMetaClass getMetaClass()getter method I suppose, because there is no mapping likea.metaClass = b.metaClassresolved.a.property = b.propertygets resolved because ofObject getProperty(String var1)method.Solution
This problem can be solved by specifying explicitly
ExplodingIntrospectorfor your mapping script that:All you have to do is to add
right below
mappingFor a: ..., b: ...header. For example:Tested with two Groovy classes, worked like a charm. Hope it helps.