1

My requirement was to map one Java Object to another. But this was conditional mapping as follows

// Create Y from data in X // If X has a=A and b=B then set p=P in Y else set p=P' // If X has c that starts with "CC" then set q=Q in Y else set q=Q' // so on 

I explored Dozer & MapStruct, but did not find them apt for supporting above conditions without polluting code with lot of annotations.

Is there any library that cleanly abstracts out such conditional mappings or rules. I mean, some framework that executes rules in a sequence and finally ends up creating Y from X

// Here ChainOfTransformers may be configuration driven transformation logic ExpectedLibrary.map(SourceEntity, DestinationEntity, ChainOfTransformers) 

Please point me to open source units that I can explore

1
  • Since the logic you obviously do have seems to be quite complicated, why not take the generated output of e.g. MapStruct and enrich it with your own logic? Commented May 4, 2016 at 19:08

1 Answer 1

1

When using MapStruct, you might take a look at decorators and after-mapping callbacks. Both allow you to perform additional mapping logic from hand.

Personally I think you are better of by implementing these routines using plain Java code instead of some kind of "configured rules".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.