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 usesReflectionIntrospector
and what's important:A simple Groovy class like:
gets compiled to a Java class that implements
GroovyObject
providing following methods:In this case
ReflectionInstanceCreator
combined withautomap()
resolves following mappings:and
where
a = b
mapping comes fromMetaClass getMetaClass()
getter method I suppose, because there is no mapping likea.metaClass = b.metaClass
resolved.a.property = b.property
gets resolved because ofObject getProperty(String var1)
method.Solution
This problem can be solved by specifying explicitly
ExplodingIntrospector
for 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.