SlideShare a Scribd company logo
Mule ESB
How to use Jackson in Json to Object converter
Gennaro Spagnoli - 2016
In this tutorial we will be creating an easy json to object converter using Jackson annotations
in order to have major control on the fields datamapping.
As usual, let’s begin creating the http inbound component to get the input JSON
Suppose now we will have this json in input:
{ "name" : "Gennaro", "surname" : "Spagnoli", "profession" : "programmer"}
We want to transform this json to this java object:
package com.mulechampion;
import java.io.Serializable;
public class JsonClass implements Serializable{
/**
*
*/
private static final long serialVersionUID = -5645625751838751914L;
private String fullName;
private String fullSurname;
private String job;
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getFullSurname() {
return fullSurname;
}
public void setFullSurname(String fullSurname) {
this.fullSurname = fullSurname;
}
public String getJob() {
return job;
}
public void setJob(String job) {
this.job = job;
}
@Override
public String toString() {
return "JsonClass [fullName=" + fullName + ", fullSurname="
+ fullSurname + ", job=" + job + "]";
}
}
The problem here is that there’s no automatic field mapping based on the fields name,
resulting in the following error, if we start the application with this flow:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "name"
(Class com.mulechampion.JsonClass), not marked as ignorable
To solve this, we will use Jackson annotations in this way:
@JsonProperty(value="name")
private String fullName;
@JsonProperty(value="surname")
private String fullSurname;
@JsonProperty(value="profession")
private String job;
If we start now the application we will finally obtain the following output on the console:
HTTP_Listener_Configuration.worker.01]
org.mule.api.processor.LoggerMessageProcessor: JsonClass [fullName=Gennaro,
fullSurname=Spagnoli, job=programmer]

More Related Content

PPTX
Mule esb How to convert from Object to Json in 5 minutes
PPTX
Mule esb How to use Jackson in Object to Json converter
PPTX
Mule esb - How to convert from Json to Object in 5 minutes
PPTX
Mule esb object_to_jackson_json
PPTX
Json to json transformation in mule
PPTX
Converting with custom transformer
PPTX
Converting with custom transformer part 2
PPTX
Converting with custom transformer
 
Mule esb How to convert from Object to Json in 5 minutes
Mule esb How to use Jackson in Object to Json converter
Mule esb - How to convert from Json to Object in 5 minutes
Mule esb object_to_jackson_json
Json to json transformation in mule
Converting with custom transformer
Converting with custom transformer part 2
Converting with custom transformer
 

What's hot (10)

PPTX
Mule esb data weave multi input data
PPTX
Mapping and listing in mule
PPTX
Mule parsing with json
PPTX
Xslt in mule
PPTX
Converting with custom transformer
PPTX
Splitting with mule part2
PPTX
Mapping and listing with mule
PPTX
Web Services
PPTX
Input and output flow using http and java component
PPTX
Mapping and listing with mule
Mule esb data weave multi input data
Mapping and listing in mule
Mule parsing with json
Xslt in mule
Converting with custom transformer
Splitting with mule part2
Mapping and listing with mule
Web Services
Input and output flow using http and java component
Mapping and listing with mule
Ad

Viewers also liked (8)

PPTX
Mule errors
PPTX
Concepts in mule
PPTX
Enterprise service bus mule
PPTX
Mule requestor component
PPT
Mule anypointenterprisesecurity
PPTX
Mule esb How to convert from CSV to Json in 5 minutes
PPT
Anypoint vpc
PPTX
Encrption in mule
Mule errors
Concepts in mule
Enterprise service bus mule
Mule requestor component
Mule anypointenterprisesecurity
Mule esb How to convert from CSV to Json in 5 minutes
Anypoint vpc
Encrption in mule
Ad

More from Gennaro Spagnoli (8)

PPTX
Mule esb How to use Collection Splitter in 5 minutes
PPTX
Mule esb - How to use Idempotent Filters in 5 minutes
PPTX
Mule esb How to convert from Json to Xml in 5 minutes
PPTX
Mule ESB - How to convert from Xml to Json in 5 minutes
PPTX
Mule esb - How to make CRUD operations to a MySql Database in 5 minutes
PPTX
Mule esb - How to connect to a MySql Database in 5 minutes
PPTX
Mule esb soap_service
PPTX
Mule esb How to use Collection Splitter in 5 minutes
Mule esb - How to use Idempotent Filters in 5 minutes
Mule esb How to convert from Json to Xml in 5 minutes
Mule ESB - How to convert from Xml to Json in 5 minutes
Mule esb - How to make CRUD operations to a MySql Database in 5 minutes
Mule esb - How to connect to a MySql Database in 5 minutes
Mule esb soap_service

Recently uploaded (20)

PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
Internet___Basics___Styled_ presentation
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
artificial intelligence overview of it and more
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PPTX
Introduction to Information and Communication Technology
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
Paper PDF World Game (s) Great Redesign.pdf
Internet___Basics___Styled_ presentation
presentation_pfe-universite-molay-seltan.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
international classification of diseases ICD-10 review PPT.pptx
Power Point - Lesson 3_2.pptx grad school presentation
Tenda Login Guide: Access Your Router in 5 Easy Steps
artificial intelligence overview of it and more
WebRTC in SignalWire - troubleshooting media negotiation
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
Introduction to Information and Communication Technology
Introuction about ICD -10 and ICD-11 PPT.pptx
introduction about ICD -10 & ICD-11 ppt.pptx
SAP Ariba Sourcing PPT for learning material
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
RPKI Status Update, presented by Makito Lay at IDNOG 10
Decoding a Decade: 10 Years of Applied CTI Discipline
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx

Mule esb How to use Jackson in Json to Object converter

  • 1. Mule ESB How to use Jackson in Json to Object converter Gennaro Spagnoli - 2016
  • 2. In this tutorial we will be creating an easy json to object converter using Jackson annotations in order to have major control on the fields datamapping. As usual, let’s begin creating the http inbound component to get the input JSON Suppose now we will have this json in input: { "name" : "Gennaro", "surname" : "Spagnoli", "profession" : "programmer"}
  • 3. We want to transform this json to this java object: package com.mulechampion; import java.io.Serializable; public class JsonClass implements Serializable{ /** * */ private static final long serialVersionUID = -5645625751838751914L; private String fullName; private String fullSurname; private String job; public String getFullName() { return fullName; } public void setFullName(String fullName) { this.fullName = fullName; } public String getFullSurname() { return fullSurname; } public void setFullSurname(String fullSurname) { this.fullSurname = fullSurname; } public String getJob() { return job; } public void setJob(String job) { this.job = job; } @Override public String toString() { return "JsonClass [fullName=" + fullName + ", fullSurname=" + fullSurname + ", job=" + job + "]"; } }
  • 4. The problem here is that there’s no automatic field mapping based on the fields name, resulting in the following error, if we start the application with this flow: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "name" (Class com.mulechampion.JsonClass), not marked as ignorable To solve this, we will use Jackson annotations in this way: @JsonProperty(value="name") private String fullName; @JsonProperty(value="surname") private String fullSurname; @JsonProperty(value="profession") private String job;
  • 5. If we start now the application we will finally obtain the following output on the console: HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: JsonClass [fullName=Gennaro, fullSurname=Spagnoli, job=programmer]