java - How to configure Orika classMap for class hierarchies? -
java - How to configure Orika classMap for class hierarchies? -
i'm trying understand how configure orika class mapping correctly in case have inheriting classes.
i've set simple illustration ba able understand working , not working, not it.
public class source { private final string alpha; public source(final string alpha) { this.alpha = alpha; } public string getalpha() { homecoming alpha; } } public final class sourceextended extends source { private final string beta; public sourceextended(final string alpha, final string beta) { super(alpha); this.beta = beta; } public string getbeta() { homecoming beta; } } public final class target { private final string alpha; private final string beta; public target (final string alpha) { this(alpha, null); } public target(final string alpha, final string beta) { this.alpha = alpha; this.beta = beta; } public string getalpha() { homecoming alpha; } public string getbeta() { homecoming beta; } }
i'm doing mapping follows
source s = new source("alpha"); target t = this.mapper.map(s, target.class); sourceextended s = new sourceextended("alpha", "beta"); target t = this.mapper.map(s, target.class);
and have tried next configurations...
factory.classmap(sourceextended.class, target.class) .bydefault() .register(); factory.classmap(source.class, target.class) .bydefault() .register();
result: both mappings compile , run, beta not set in target sourceextended object, mapping sourceextended not working.
so thought if explicitly state constructor used, beta should mapped too:
factory.classmap(sourceextended.class, target.class) .bydefault() .constructora("alpha", "beta") .constructorb("alpha", "beta") .register(); factory.classmap(source.class, target.class) .bydefault() .register();
but result same. beta not mapped. , not alter if replace default mapping specifying fields or adding constructor mapping configuration of source.class.
can give me hint how configure such mapping? thanks!
kind regards, jose
yep, can utilize classmapbuilder.use
automatically utilize existing mappings on parent classes.
here had existing mapping ticketentity
conversation
, want map new detailedconversation
(that has fields) , did so:
mapperfactory.classmap(ticketentity.class, detailedconversation.class) .use(ticketentity.class, conversation.class) .customize(conversationmapper()) .bydefault() .register();
java mapping orika
Comments
Post a Comment