Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>google-gson</code>. Details:</p> <p><strong>Object Examples</strong></p> <pre><code>class BagOfPrimitives { private int value1 = 1; private String value2 = "abc"; private transient int value3 = 3; BagOfPrimitives() { // no-args constructor } } </code></pre> <p><strong>(Serialization)</strong></p> <pre><code>BagOfPrimitives obj = new BagOfPrimitives(); Gson gson = new Gson(); String json = gson.toJson(obj); ==&gt; json is {"value1":1,"value2":"abc"} </code></pre> <p>Note that you can not serialize objects with circular references since that will result in infinite recursion.</p> <p><strong>(Deserialization)</strong></p> <pre><code>BagOfPrimitives obj2 = gson.fromJson(json, BagOfPrimitives.class); ==&gt; obj2 is just like obj </code></pre> <p><em><strong>Another example for Gson:</em></strong></p> <p>Gson is easy to learn and implement, you need to know is the following two methods:</p> <p>-> toJson() – convert java object to JSON format</p> <p>-> fromJson() – convert JSON into java object</p> <pre><code>import com.google.gson.Gson; public class TestObjectToJson { private int data1 = 100; private String data2 = "hello"; public static void main(String[] args) { TestObjectToJson obj = new TestObjectToJson(); Gson gson = new Gson(); //convert java object to JSON format String json = gson.toJson(obj); System.out.println(json); } } </code></pre> <p><strong>Output</strong></p> <pre><code>{"data1":100,"data2":"hello"} </code></pre> <p><strong>Resources:</strong> </p> <p><a href="http://code.google.com/p/google-gson/">Google Gson Project Home Page</a> </p> <p><a href="http://sites.google.com/site/gson/gson-user-guide">Gson User Guide</a></p> <p><a href="http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/">Example</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload