1
votes

enter image description hereI have an input xml and it has only one Telephone child element,

<ContactMethod>
                <Telephone type="fax">
                    <Number>String</Number>
                    <Extension>String</Extension>
                </Telephone>
</ContactMethod>

But my output XML has multiple Telephone child element,

<ContactMethod>
                    <Telephone type="fax">
                        <Number>String</Number>
                        <Extension>String</Extension>
                    </Telephone>
                    <Telephone type="fax">
                        <Number>String</Number>
                        <Extension>String</Extension>
                    </Telephone>
    </ContactMethod>

I want to map from input element Number to output Number and also Extension element.

I can't change the schema because it is globally used.

I don't see any options to map using Element Mapping.

And I tried using adding Rule to the ContactMethod element, but no luck.

......

Above I is just example I asked. I need one to many mapping idea in datamapper.

See attached image, that is my actual requirement. Look at the Disclosure/CandidateDisclosure elements in source and destination

My source is XML and target is JSON, but the actual logic I need is similar for all the structures ..

1
Can you review your snippets? it looks like you just want to duplicate the input - VĂ­ctor Romero
My source is xml and target is json.. Just for understanding I explained both are xml. - Sahal
@VĂ­ctorRomero I edited the question .. - Sahal

1 Answers

0
votes

I am maintaining a project which use DataMapper and faced the same issue. To solve it I add Java Transformer (you can use Groovy or other scripting languages) after DataMapper to group the one-to-many relationship.

Following is the pseudo code:

 provide empty telpMap

 foreach telpXml which is extracted from src/payload {
     key = telpXml.get("@type");
     if (telpMap.containsKey(key)) {
         List number = telpMap.get(key).get("Number");
         number.addAll(telpXml.get("Number"));
         List extension = telpMap.get(key).get("Extension");
         extension.addAll(telpXml.get("Extension"));
     } else {
         telpMap.put(key, telpXml);
     }
 }

 return telpMap.values();