DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Introduction to Polymorphism With Database Engines in NoSQL Using Jakarta NoSQL
  • JSON Handling With GSON in Java With OOP Essence
  • Proper Java Exception Handling
  • Postgres JSON Functions With Hibernate 6

Trending

  • AI Meets Vector Databases: Redefining Data Retrieval in the Age of Intelligence
  • Understanding Java Signals
  • Microsoft Azure Synapse Analytics: Scaling Hurdles and Limitations
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  1. DZone
  2. Coding
  3. Languages
  4. Payload Transformation: JSON to Java

Payload Transformation: JSON to Java

Read on to view this tutorial in order to learn how to transform input data in the form of JSON to Java to increase efficiency and reduce execution time.

By 
Varun Goyal user avatar
Varun Goyal
·
May. 22, 18 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
19.7K Views

Join the DZone community and get the full member experience.

Join For Free

Mule provides us the functionality of transforming one input data type to another that not only increases the system efficiency but also reduces the execution time. The request is passed in different formats, namely XML, JSON, etc.

Here, in the code, the input data is passed in the form of JSON and transformed output as Java LinkedHashMap, which reduces the time of defining the Java class and referencing to it every time the request is sent. The HTTP Listener configuration can be set as port availability.

Image title

The request data sent is captured and set in the payload for Java transformation using Transform Message.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 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/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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://www.mulesoft.org/schema/mule/http 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:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="jsontojavaFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <set-payload value="#[payload]" doc:name="Set Payload"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
Name: payload.Name,
Profile: payload.Profile,
Module_date: payload.Module_date
}]]></dw:set-payload>
        </dw:transform-message>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

The transformation from JSON to Java is done and the result is logged using Logger.

Request URI: http://localhost:8081/jsontojava

POST:

[
{
"Name" : "Varun",
"Profile" : "Developer",
"Module_date" : "04/12/2017"
},
{
"Name" : "Puja",
"Profile" : "Tester",
"Module_date" : "08/11/2017"
}
]

Response:

Image title

The response is coming as per expectation, which not only increases code efficiency but also performance.

JSON Java (programming language) Payload (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Introduction to Polymorphism With Database Engines in NoSQL Using Jakarta NoSQL
  • JSON Handling With GSON in Java With OOP Essence
  • Proper Java Exception Handling
  • Postgres JSON Functions With Hibernate 6

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!