Convert Object as Json using FasterXML/jackson-jr

Its an alternative to jackson-bind API for processing JSON. It provides an easy way to convert the java object to json and vice versa.

This API can be used, when the size of the third party jar and startup time matters in your application. This API has very low initialization overhead compared to jackson-bind

The Github repository is



Sample code to convert the Object to json is given below,

import com.fasterxml.jackson.jr.ob.JSON;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class JSONUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(JSONUtils.class);

    public static void main(String[] args) throws IOException {"Converting Object to String");
        Customer customer = new Customer();
        String objectString = convertObjectAsString(customer);"Converting String:{}", objectString);"Converting String to Customer Object");
        Customer customer1 = convertJsonStringAsObject(objectString);"Converted Object:{}", customer1);


    public static String convertObjectAsString(Object obj) throws IOException {
        return JSON.std.asString(obj);

    public static Customer convertJsonStringAsObject(String content) throws IOException {
        return JSON.std.beanFrom(Customer.class, content);

    public static class Customer {

        private String firstName;
        private String lastName;
        private String customerId;

        public String getFirstName() {
            return firstName;

        public void setFirstName(String firstName) {
            this.firstName = firstName;

        public String getLastName() {
            return lastName;

        public void setLastName(String lastName) {
            this.lastName = lastName;

        public String getCustomerId() {
            return customerId;

        public void setCustomerId(String customerId) {
            this.customerId = customerId;


        public boolean equals(Object o) {
            if (this == o) return true;

            if (o == null || getClass() != o.getClass()) return false;

            Customer customer = (Customer) o;

            return new EqualsBuilder()
                    .append(firstName, customer.firstName)
                    .append(lastName, customer.lastName)
                    .append(customerId, customer.customerId)

        public int hashCode() {
            return new HashCodeBuilder(17, 37)

        public String toString() {
            return new ToStringBuilder(this)
                    .append("firstName", firstName)
                    .append("lastName", lastName)
                    .append("customerId", customerId)



2016-12-29T11:44:54.319-0500 [main] INFO  o.c.o.m.JSONUtils - Converting Object to String
2016-12-29T11:44:54.398-0500 [main] INFO  o.c.o.m.JSONUtils - Converting String:{"customerId":"cust1234","firstName":"Bala","lastName":"samy"}
2016-12-29T11:44:54.399-0500 [main] INFO  o.c.o.m.JSONUtils - Converting String to Customer Object
2016-12-29T11:44:54.405-0500 [main] INFO  o.c.o.m.JSONUtils - Converted$Customer@31ef45e3[firstName=Bala,lastName=samy,customerId=cust1234]