Convert Java Object To / From JSON, Jackson Example

Convert Java Object To / From JSON, Jackson Example explains about converting a Java Object to JSON string, JSON string to Java Object Using Jackson JSON library

Consider an example where you need to pass the request as JSON string, In this situation you can easily serialize the Java Object to JSON string and vice versa

According to Jackson documentation, Jackson is a multi-purpose Java library for processing JSON data format. Jackson aims to be the best possible combination of fast, correct, lightweight, and ergonomic for developers.

Reference -> https://github.com/FasterXML/jackson/

Here I am showing an example about How to convert a Java Object to JSON string and vice versa using Jackson processor.

CXF Convert Number To String

CXF Convert Number To String explains about resolving the issue on serialization when the value of a string is integer when using jettison library

Jettison is an open source java library for processing JSON format. It is the default library bundled with CXF framework, the problem with jettison is that if value of a string is integer type, it automatically convert that string to integer type. By removing the quotes between that number

if the string values is "12345"
{"Student":{"name":"12345"}}
it automatically convert to below value
you can see that quotes are removed even the type of that object is string
{"Student":{"name":12345}}

Apache CXF With Jackson

Apache CXF With Jackson Example explains step by step details of configuring Apache CXF With Jackson Provider

JAX-RS is Java API for RESTful Webservices which is very rely upon Representational State Transfer model, you can view JAX-RS specification 

Jackson is an open source java library for processing JSON format. We can use Jackson library by replacing Jettison, which is the default library for CXF

You can see the below example, which is demonstrating How to configure a Restful service using Jackson library by replacing default jettison library which is available with cxf bundle

You can also see Restful service using Jettison library CXF Restful Tutorial.