Home » Core Java » json

json

Jackson vs Gson: A Deep Dive

This is a tutorial about Jackson vs Gson. Specifically, we will do a quick comparison of the libraries Gson and Jackson for serialization of a Java object to its JSON representation and deserialization of JSON string back to an equivalent Java object. We will talk about the benefits of each and see which library to use when. 1. Maven Dependencies ...

Read More »

Jackson Bidirectional Relationships

In this example, we will go through the Infinite Recursion (StackOverflowError) problem, when working with Bidirectional Relationships in Jackson model classes. We will also see different techniques to serialize and deserialize such entities. If you are new to Jackson, it is good to go through this primer on ObjectMapper before proceeding with this example. 1. What is a Bidirectional Relationship? ...

Read More »

Jackson Exceptions – Problems and Solutions

1. Introduction In this example, we shall go through the most common Jackson API exceptions encountered while working for serialization and deserialization. We will see what caused the exception to be thrown and how to fix it. Let’s dive deep. Table Of Contents 1. Introduction 2. InvalidDefinitionException: No Creators, like default constructor, exist 3. MismatchedInputException: Out of START_ARRAY token 4. ...

Read More »

Jackson Annotation Examples

This example is a deep dive into Jackson Annotations. It covers almost all the annotations with code examples. We will learn how to use the existing annotations, create our custom annotations and finally how to completely disable Jackson annotations. If you are new to the Jackson API for JSON serialization and deserialization, check out this article on Introduction to Jackson ...

Read More »

Introduction to Jackson ObjectMapper

In this example, we will learn about the ObjectMapper class from Jackson and its capabilities to serialize POJOs(Plain Old Java Objects) into JSON strings and deserialize JSON strings back into Java objects, with some examples. 1. Where To Start? The first step to getting our hands dirty with ObjectMapper and Jackson data binding is to get the libraries and add ...

Read More »

Read JSON From a URL Example Using Data Pipeline

I have a problem. I want to read JSON from a URL. Naturally, like anybody else, I googled for some solutions. There were a lot of solutions shared in Stack Overflow and other sites. I tried some of them but I’d like to share the one where I used the Data Pipeline Java library. 1. Tools and Prerequisites Data Pipeline ...

Read More »

Java JSON parser Example

In this post, we feature a comprehensive Java JSON parser Example. JSON is simply a text format that facilitates reading and writing. It is a widely used data-interchange language because its parsing and its generation is easy for machines. In Java language there are many ways for JSON processing. 1. JSON Parsers In this section we will see four different ...

Read More »

JSON.Simple Example to read and write JSON in Java

In this example we are going to see a very nice JSON framwork, JSON.simple. In this tutorial we are going to see how to read and write JSON to file using this framework, and you will notice yourself how simple :) it really is. 1. JSON.simple library and dependencies If your are using Maven to build your project, you just ...

Read More »

Enable Pretty Print JSON Output using Jackson example

As you might have noticed in the previous JSON tutorials, the output of the programs is not properly aligned, which makes it hard to read. For this demonstration we are going to use the Student class from this example.             Student.java: package com.javacodegeeks.java.core; public class Student { private int id; private String firstName; private String ...

Read More »

Jackson Streaming API to read and write JSON example

Jackson project has implemented a very useful Streaming API which is also called incremental mode. This is the most efficient way to process JSON content. It has the lowest memory and processing overhead, and can often match performance of many binary data formats available on Java platform. It’s a bit tricky to use though because you have to handle JSON ...

Read More »