GOOGLE GSON / CATATAN</>↗Google Gson04 Feb 2010
In the example below you can see how to convert an array into JSON string. We serialize the array to JSON using the Gson.toJson() method. To deserialize a string of JSON into array we use the Gson.fromJson() method. package org.kodejava.gson; import com.google.gson.Gson; public class ArrayToJson { public static void main(String[] args) { int[] numbers = […]
GOOGLE GSON / CATATAN</>↗Google Gson03 Feb 2010
In this example you’ll see how the Gson library handles the object fields. For object fields to be serialized into JSON string it doesn’t need to use any annotations, it can even read private fields. If you have a null value field it will not be serialized into JSON string. To exclude a field from […]
GOOGLE GSON / CATATAN</>↗Google Gson01 Feb 2010
On the previous example, How do I convert object into JSON? we convert object into JSON string. In this example you will see how to do the opposite, converting JSON string back into object. To convert JSON string to object use Gson.fromJson() method. This method takes the JSON string and the object type of the […]
GOOGLE GSON / CATATAN</>↗Google Gson30 Jan 2010
In this example we are using Google Gson to convert an object (Student object) into JSON notation. Practically we can use this library to convert any object in Java, and it is quite simple. You just need to create an instance of Gson class and then call the toJson() method and pass the object to […]
CORE API / CATATAN</>↗Core API27 Jan 2010
The code below demonstrates how to create a progress bar in a console program. The trick is to print the progress status using a System.out.print() and add a carriage return character ("\r") at the end of the string to return the cursor position to the beginning of the line and print the next progress status. […]
CORE API / CATATAN</>↗Core API23 Jan 2010
This example demonstrates how to use the System.nanoTime() method to calculate processing execution time in higher resolution. The processing time calculated in nanoseconds resolution. package org.kodejava.lang; public class NanoSecondsTimerResolution { public static void main(String[] args) { // Get process execution start time in nanoseconds. long start = System.nanoTime(); System.out.println("Process start… " + start); try { […]