SlideShare a Scribd company logo
XML to Object transformation in Mule
with Dataweave
As we know, there can be multiple types of payload
we need to deal daily, starting from JSON, XML or
String, we also require different type of data
transformation in our application like XML to JSON,
JSON to XML or String etc . In Mule application, we
have a various set of transformers that we can use to
obtain our required data format.
Today we will be discussing on transformation of XML
to Object format of data.
So, let us consider, we have the following XML
payload as an input to our application
< user>
<name>John</name>
<lastName>Rich</lastName>
</user>
Mule source
<?xml version="1.0" encoding="UTF-8"?>
<mule
xmlns:metadata=http://www.mulesoft.org/schema/mule/metad
ata
xmlns:http=http://www.mulesoft.org/schema/mule/http
xmlns:http=http://www.mulesoft.org/schema/mule/http
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc=http://www.mulesoft.org/schema/mule/documentati
on
xmlns:spring=http://www.springframework.org/schema/beans
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/htt
p http://www.mulesoft.org/schema/mule/http/current/mule-
http.xsd
http://www.mulesoft.org/schema/mule/ee/dw
http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-
current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<http:listener-config name="HTTP_Listener_Configuration"
host="0.0.0.0" port="8081" doc:name="HTTP Listener
Configuration"/>
<flow name="testweaveFlow">
<http:listener config-ref="HTTP_Listener_Configuration"
path="/test" doc:name="HTTP"/>
<dw:transform-message doc:name="Transform Message">
<dw:input-payload doc:sample="empty.xml"/>
<dw:set-payload><![CDATA[%dw 1.0
%type user = :object { class: "testdatajava.User" }
%output application/java
---
{
firstName: payload.user.name,
lastName: payload.user.lastName
} as :user]]></dw:set-payload>
</dw:transform-message>
<byte-array-to-string-transformer doc:name="Byte Array to
String"/>
<logger message="#[message]" level="INFO"
doc:name="Logger"/>
</flow>
</mule>
In the transform code I created the Object type in the header
“ %type user = :object { class: "testdatajava.User"} ”
And the payload of the transform is converted to User Object
using the transform logic as below.
{
firstName: payload.user.name,
lastName: payload.user.lastName
} as :user
Transformer
User.java
public class User {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return this.firstName + " " + this.lastName;
}
}
Mule Flow

More Related Content

PPTX
Transformation xmltoobjectesb
PPTX
Transformation xmltoobjectesb
PPTX
Xml toobjectesbtransform
PPTX
WebServices Basic Overview
PPTX
Introduction to WebServices
PPTX
Introduction to WebServices
ODT
Rest With Json Vs Soap With Xml
PPT
My Sql
Transformation xmltoobjectesb
Transformation xmltoobjectesb
Xml toobjectesbtransform
WebServices Basic Overview
Introduction to WebServices
Introduction to WebServices
Rest With Json Vs Soap With Xml
My Sql

Viewers also liked (17)

PPTX
Example esb flow
PPTX
Transformation csvtoxml
PPTX
Transformation jsontojsonesb
PPTX
Esb first http flow
PPTX
Transformation jsontoxmlesb
PPTX
Create web services jax - ws1
DOCX
Plunge for Hunger article
PPTX
Http component
PPTX
Rest fullservices
PPTX
Create web services jax - ws2
PPTX
Example esb file-to-string flow
PPTX
Example esb flow
PPTX
Create web services jax - ws3
PPTX
Зустріч 2016 "На крилах спогадів"
PPTX
Configurare https mule
PPTX
Json to json transformation in mule
PPTX
Configurare http mule
Example esb flow
Transformation csvtoxml
Transformation jsontojsonesb
Esb first http flow
Transformation jsontoxmlesb
Create web services jax - ws1
Plunge for Hunger article
Http component
Rest fullservices
Create web services jax - ws2
Example esb file-to-string flow
Example esb flow
Create web services jax - ws3
Зустріч 2016 "На крилах спогадів"
Configurare https mule
Json to json transformation in mule
Configurare http mule
Ad

Similar to Transformation xmltoobjectesb (20)

PPTX
Mule XML java sample
PPTX
Mulexml java
PPTX
Mule Esb Data Weave
PPTX
Mule esb DataWeave
PPTX
Mule esb dataweave
PPTX
Mule esb Data Weave
 
PPTX
Mule esb:DataWeave
PPTX
Mule esb
PPTX
Mule esb
PPTX
Mule esb
PPTX
Mule esb
PPTX
Mule esb :Data Weave
PPTX
Mule esb
PPTX
Mule esb :Data Weave
PPTX
Mule xml java
PPTX
Xml to xml transformation in mule
PPTX
Mule xml java
PPTX
Json to xml esb transformation
PDF
MuleSoft DataWeave data transformation language
PPTX
Xml to xml transformation in mule
Mule XML java sample
Mulexml java
Mule Esb Data Weave
Mule esb DataWeave
Mule esb dataweave
Mule esb Data Weave
 
Mule esb:DataWeave
Mule esb
Mule esb
Mule esb
Mule esb
Mule esb :Data Weave
Mule esb
Mule esb :Data Weave
Mule xml java
Xml to xml transformation in mule
Mule xml java
Json to xml esb transformation
MuleSoft DataWeave data transformation language
Xml to xml transformation in mule
Ad

Recently uploaded (20)

PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPT
introduction to datamining and warehousing
PDF
composite construction of structures.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
573137875-Attendance-Management-System-original
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPT
Project quality management in manufacturing
PPTX
Geodesy 1.pptx...............................................
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
PPT on Performance Review to get promotions
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CYBER-CRIMES AND SECURITY A guide to understanding
introduction to datamining and warehousing
composite construction of structures.pdf
Digital Logic Computer Design lecture notes
R24 SURVEYING LAB MANUAL for civil enggi
Foundation to blockchain - A guide to Blockchain Tech
573137875-Attendance-Management-System-original
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CH1 Production IntroductoryConcepts.pptx
Safety Seminar civil to be ensured for safe working.
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Project quality management in manufacturing
Geodesy 1.pptx...............................................
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT on Performance Review to get promotions

Transformation xmltoobjectesb