DZone
Java Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Easy Conversion of HTTP Payloads

Easy Conversion of HTTP Payloads

Payload, a new tool up on GitHub, promises to serialize and deserialize data without the need to use third-party libraries like Jackson or Gson.

Juliano Mohr user avatar by
Juliano Mohr
·
Jun. 27, 17 · Java Zone · News
Like (4)
Save
Tweet
6.32K Views

Join the DZone community and get the full member experience.

Join For Free

Almost every application needs to handle data in an interchangeable format. In the world of HTTP JSON-based APIs, the task of serializing and deserializing the payloads is something usually delegated to a third party library. Some examples are Jackson, Gson, and the most recent Java EE spec JsonP. What if there was a way where applications can be decoupled from these providers in a similar fashion to how SLF4J does for logging? That's the goal of Payload.

<dependency>
    <groupId>com.juliaaano</groupId>
    <artifactId>payload</artifactId>
    <version>${check.latest}</version>
</dependency>


// Serialization
Payload<MyObject> payload = 
JSON.payload().newInstance(new MyObject());
String json = payload.raw();
// Deserialization
Payload<MyObject> payload =
XML.payload().newInstance(xmlAsString, MyObject.class);
MyObject obj = payload.get();


The design is quite flexible in the way it can accommodate custom implementations of the mechanism that does the conversion. I call it the Provider in this context. Click here to understand more about providers.

Testing is something that you might want to use this library for. The ability to swap the underlying provider gives you a way to assemble your JSON test data using a different instrument rather than the one used in production, but while still keeping the same API.

No major performance drawbacks have been identified by using Payload instead of directly employing Jackson or Gson. The project contains a few JUnit [benchmark tests] to address the matter.

I have created a very small app as a proof of concept for this project: Payload Tests. There, you can see how things are expected to work, including the implementation of a custom provider.

Great effort has been put into the design aspect. It is fair to mention that the main motivation behind this initiative was actually to exercise good practices such as object composition, OOP, and building a pipeline to continuously release in Maven Central, just to name a few. If you have read this far and have also found value in what has been built, I'd be more than happy to accept your contributions. Keep coding!

Payload (computing)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Ultra-Fast Microservices: When Microstream Meets Wildfly
  • Choosing Between GraphQL Vs REST
  • Why I'm Choosing Pulumi Over Terraform
  • Synchronization Methods for Many-To-Many Associations

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo