Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mule esb How to convert from Object to Json in 5 minutes

Mule esb How to convert from Object to Json in 5 minutes

  • Login to see the comments

  • Be the first to like this

Mule esb How to convert from Object to Json in 5 minutes

  1. 1. Mule ESB How to convert from Object to Json in 5 minutes Gennaro Spagnoli - 2016
  2. 2. Gennaro Spagnoli - 2016 In this tutorial we will be creating an easy object to json converter using mule esb. Let’s begin creating a simple flow with an http listener, in order to trigger the transformation: Now, let’s create a java pojo class, called User, like this:
  3. 3. Gennaro Spagnoli - 2016 package com.mulechampion; import java.io.Serializable; public class JsonClass implements Serializable{ /** * */ private static final long serialVersionUID = -5645625751838751914L; private String name; private String surname; public JsonClass(String name, String surname) { super(); this.name = name; this.surname = surname; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSurname() { return surname; } public void setSurnme(String surnme) { this.surname = surnme; } @Override public String toString() { return "JsonClass [name=" + name + ", surname=" + surname + "]"; } }
  4. 4. Gennaro Spagnoli - 2016 Now we can use the setPayload component to populate the bean created before: As expected, running this app, will produce the following log on console: HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: JsonClass [name=Gennaro, surname=Spagnoli]
  5. 5. Now let’s add the Object-to-json transformer in order to obtain the output JSON If we launch the application, calling it, we will obtain the json output, as wanted! HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: {"name":"Gennaro","surname":"Spagnoli"}

×