Saturday, May 23, 2015

GSON with liferay

GSON is a Java API, developed by Google, used to convert between Java objects and JSON objects. This article discusses and provides simple code examples using this API. More information about this API can be found at: http://sites.google.com/site/gson/.

This is the first article from a series of articles about GSON. No GSON or JSON experience is required as this article acts as a primer for the other articles. The second article provides more examples about the use of GSON deserializer (from JSON to Java) and the third article provides more examples about the GSON serializer (from Java to JSON).

All code listed below is available at: https://java-creed-examples.googlecode.com/svn/gson/Simple%20Gson%20Example. Most of the examples will not contain the whole code and may omit fragments which are not relevant to the example being discussed. The readers can download or view all code from the above link.
The reader needs to have a basic knowledge of Java (tutorial) and a very basic knowledge of Maven (Homepage). The code listed here makes use of maven to download the GSON library. Checking out the project into Springsource Tool Suite (the recommended IDE) will work without having to configure anything.

Download and Install: 

Before you can do any work with this API, you need to download the library (jar file) and include it in the classpath. The library, together with the source and JavaDocs, can be downloaded from: http://code.google.com/p/google-gson/downloads/list. Once downloaded, add the gson-<version>.jar to the classpath. For those readers who prefer to use Maven to manage the dependencies (JAR files), add the following dependency to the pom.xml.
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.2.4</version>
</dependency>

http://www.javacreed.com/simple-gson-example/

No comments:

Post a Comment