JACKSON / NOTES</>↗Jackson13 Feb 2017
The following example demonstrate how to serialize and deserialize Java object to JSON file. The Jackson’s ObjectMapper class provides writeValue(File, Object) and readValue(File, Class<T>) methods which allow us to write an object into JSON file and read JSON file into an object respectively. package org.kodejava.jackson; import com.fasterxml.jackson.databind.ObjectMapper; import org.kodejava.jackson.support.Artist; import java.io.File; import java.io.IOException; public cla...
JACKSON / NOTES</>↗Jackson13 Feb 2017
In the following example we will convert JSON string to Java object using ObjectMapper class from the Jackson library. This class provides a method readValue(String, Class<T>) which will deserialize a JSON string into Java object. The first argument to the method is the JSON string and the second parameter is the result type of the […]
JACKSON / NOTES</>↗Jackson12 Feb 2017
The following example shows how to convert Java object into JSON string using Jackson. Jackson provide ObjectMapper class provides functionality to read and write JSON data. The writeValueAsString(Object) method to serialize any Java object into string. Here are the steps to convert POJOs into JSON string: Create a Java object, set some properties on it. […]
APACHE HTTPCOMPONENTS / NOTES</>↗Apache HttpComponents11 Jan 2017
This example demonstrates how to do multipart upload using the Apache HttpClient library. In this example we upload a single file. We start by creating an object of the file to be uploaded. The FileBody represent the binary body part of the file. Next, prepare the HttpEntity object by create an instance of MultipartEntityBuilder. Add […]
CORE API / NOTES</>↗Core API07 Jan 2017
You want to convert numbers into their Roman numerals representation and vice versa. The solution here is to tackle the problem as a unary problem where the Roman numerals represented as a single element, the “I” character. We start by representing the number as a repeated sequence of the “I” characters. And then replace the […]
APACHE HTTPCOMPONENTS / NOTES</>↗Apache HttpComponents06 Jan 2017
The following code snippet show you how to send POST request with a JSON body using HttpClient. The payload in this example is a user information containing id, first_name and a last_name. We placed the payload in an object called StringEntity and also set its content type to ContentType.APPLICATION_FORM_URLENCODED. On the other end called by […]