Previous post useOneAsMany explained in easy example used an example to convert tree structure into flat structure by using useOneAsMany. This post will do the reverse, convert flat structure back to tree structure.
The source message type is flat structure. The target message type is tree structure. This mean Category, CatID, CatName need to be grouped based on same value. Book, BookID and BookName need to placed under corresponding Category.
The objective of the mapping is to convert below test source data (flat data) and target data (tree data):
Firstly, map the first element in target message type, which is “Category” field. Below transformed queue with 6 values and 6 contexts, into queue with 3 values and single context.
For field Book, use formatByExample to get correct context changes for each category. Example: values B1,B2,B3 under single context will group and place these 3 books under first category C1.
For field BookID and BookName, use directly one-to-one mapping only. This is because source fields have a context change, and for each target fields under Book group also always have a context change.
Done. We completed the mapping!
The technique and tips in these 2 posts to convert tree structure to flat structure and vice-versa, should be useful to tackle actual mapping development that involved different hierarchy levels. Enjoy!