JAVA 8 / CATATAN</>↗Java 813 Feb 2017
The following code snippet demonstrate how to convert java.time.LocalDate to java.util.Date and vice versa. In the first part of the code snippet we convert LocalDate to Date and back to LocalDate object. On the second part we convert LocalDateTime to Date and back to LocalDateTime object. package org.kodejava.datetime; import java.time.*; import java.util.Date; public class LocalDateToDate […]
JACKSON / CATATAN</>↗Jackson13 Feb 2017
We have a Recording class which has a Java 8 java.time.LocalDate property. We need to deserialize and serialize this property from and to JSON string. To do this we can use the @JsonDeserialize and @JsonSerialize annotations to annotate the LocalDate property of the Recording class. @JsonDeserialize(using = LocalDateDeserializer.class) @JsonSerialize(using = LocalDateSerializer.class) private LocalDate releaseDate; To […]
JACKSON / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 / CATATAN</>↗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 […]