简体   繁体   中英

XML to JSON data mapping - Child classes (sub classes) of xml is not shown to map with JSON in mule dataweave

I am creating a SOAP service which receives XML input as below.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:inv="http://bac.com/wsdl/cbl.WCC/InvolvedPartyMaintenanceServicingV001" xmlns:inf="http://bac.com/xmlschema/osa/InfrastructureV003" xmlns:bac="http://bac.com/xmlschema/cbl/bac024">
   <soapenv:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wsswssecurity-secext-1.0.xsd">
         <wsse:UsernameToken>
            <wsse:Username>*********</wsse:Username>
            <wsse:Password>XXXXX</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <inv:combineInvolvedPartiesRequest>
         <inv:osaRequestHeader>
            <inf:providerService>
               <inf:name>BCC</inf:name>
            </inf:providerService>
         </inv:osaRequestHeader>
         <inv:involvedPartyRoleSummary xsi:type="bac:CustomerRoleSummary">
            <bac:summarizedParty xsi:type="bac:IndividualSummary">
               <bac:contactPreferences>
                  <bac:prefers xsi:type="bac:PostalAddress">
                     <bac:addressLine>TEST ADDRESS LINE ONE</bac:addressLine>
                     <bac:addressLine>TESTADDRESSTWO</bac:addressLine>
                     <bac:city>MMNAGAR</bac:city>
                     <bac:countryCode>US</bac:countryCode>
                     <bac:postalCode>68293-8000</bac:postalCode>
                     <bac:state>FL</bac:state>
                  </bac:prefers>
               </bac:contactPreferences>
               <bac:involvedPartyName xsi:type="bac:IndividualName">
                  <bac:firstName>KRISHNA</bac:firstName>
                  <bac:lastName>PRASAD</bac:lastName>
                  <bac:middleNames>M</bac:middleNames>
               </bac:involvedPartyName>
               <bac:birthDate>1981-08-28</bac:birthDate>
            </bac:summarizedParty>
         </inv:involvedPartyRoleSummary>
         <inv:nonSurvivorPartyIdentifier xsi:type="bac:CustomerIdentifier">
            <bac:identifier>34234234234</bac:identifier>
         </inv:nonSurvivorPartyIdentifier>
         <inv:survivorPartyIdentifier xsi:type="bac:CustomerIdentifier">
            <bac:identifier>234234234234</bac:identifier>
            <bac:subsystemIdentifier>BCC</bac:subsystemIdentifier>
            <bac:systemIdentifier>0001</bac:systemIdentifier>
         </inv:survivorPartyIdentifier>
      </inv:combineInvolvedPartiesRequest>
   </soapenv:Body>
</soapenv:Envelope>

This XML contains many "xsi:type" elements which represents the possible subtypes. When i try to convert this xml to json, i am not able to find subtypes (child classes) in dataweave transform component.

For example: "postaladdress" is subclass of "contactpoint" abstract class. In transform message component, fields from "contactpoint" is shown but fields from "postaladdress" is not shown for mapping.Therefore am not able to map fields in postaladdress class to json.

Kindly help me how to do mapping for this scenario?

I handled this problem by writing a java function and calling it from dataweave (Refer global functions and calling java functions from it). That function will do "instanceof" check for child subtypes and return boolean.

Based on the boolean value, fields are populated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM