Home » JSON » Page 4

Tag Archives: JSON

JUnit Hamcrest Matcher for JSON

This post shows how you can write JUnit tests to check if an object matches a JSON string. This is important if you are implementing REST services and want to test if your service produces the expected JSON response. A useful library for comparing JSON objects is JSONassert. First, you have to convert your Java object into a JSON string ...

Read More »

Run away from ‘null’ checks feast: doing PATCH properly with JSON Patch

Today we are going to have a conversation about REST(ful) services and APIs, more precisely, around one peculiar subject many experienced developers are struggling with. To put things into perspective, we are going to talk about web APIs, where the REST(ful) principles adhere to HTTP protocol and heavily exploit the semantics of HTTP methods and (usually but not necessarily) use ...

Read More »

How to ignore unknown properties while parsing JSON in Java – Jackson @JsonIgnoreProperties Annotation Example

One of the common problem while parsing JSON in Java using Jackson API is that it fails when your JSON contains unknown properties i.e. your Java class doesn’t have all the field corresponding to all JSON properties. For example, if you are consuming JSON from a REST Web Service and tomorrow they added a new field into JSON then your code ...

Read More »

How to map JSON collections using JPA and Hibernate

Introduction The open-source hibernate-types project allows you to map Java objects or Jackson JsonNode as JPA entity properties. Recently, thanks to our awesome contributors, we added support for type-safe collections to be persisted as JSON as well. In this article, you are going to see how to achieve this goal. Maven dependency First of all, you need to set up ...

Read More »

JSON Schema’s Role in Building and Deploying Your API

What is JSON Schema? It provides a thorough way of describing the structure and properties of any JSON value. It is supremely useful in documenting requests made to and responses from any JSON API. This article will look at its role in the software development cycle of an API. Documenting JSON Response formats Perhaps the most obvious use case for ...

Read More »

Converting XML to JSON & Raw Use in MongoDB & Spring Batch

Overview Why convert XML to JSON for raw use in MongoDB? Since MongoDB uses JSON documents in order to store records, just as tables and rows store records in a relational database, we naturally need to convert our XML to JSON. Some applications may need to store raw (unmodified) JSON because there is uncertainty in how the data will be ...

Read More »

Jackson JSON Parsing Error – UnrecognizedPropertyException: Unrecognized field, not marked as ignorable [Solved]

While parsing JSON string received from one of our RESTful web services, I was getting this error “Exception in thread “main” com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field “person” (class Hello$Person), not marked as ignorable”. After some research, I found that this is one of the common error while parsing JSON document using Jackson open source library in Java application. The error messages say that ...

Read More »

JSON Processing 1.1: 100DaysOfJavaEE8

JSON Pointer Challenge Given the JSON document in the code snippet below, what is the result of using the JSON Pointer feature from JSON-P 1.1?                 The new shape of the JSON object will be as follows: { "name": "Duke", "likes": [ "Java EE 8", "Java", "Ice Cream" ] } What is JSON ...

Read More »

What is JSON Processing (JSON-P API)?

Introduction to JSON-P in Java EE The Java API for JSON Processing 1.0 (JSR 353) is a low level, lightweight JSON parser, and generator that provides that capacity to manipulate JSON data at the property and value level. The JSR 353 provides two JSON processing models: an object model and a streaming model. Both models can generate JSON data and output ...

Read More »