2. 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.
3. 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>
10. 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
11. User.java
public class User {
private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
12. 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;
}
}