forked from cherkavi/java-code-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnterPoint.java
More file actions
executable file
·35 lines (29 loc) · 1.02 KB
/
EnterPoint.java
File metadata and controls
executable file
·35 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import com.google.gson.Gson;
/** ïðèìåð èñïîëüçîâàíèÿ JSON - ïðîñëîéêè ìåæäó ðàçëè÷íûìè ÿçûêàìè */
public class EnterPoint {
private static void out(Object value){
System.out.println(value);
}
public static void main(String[] args){
out("Serialization");
Gson gson=new Gson();
out("simple int(autopack): "+gson.toJson(1));
out("string: "+gson.toJson("abcd"));
out("long: "+gson.toJson(new Long(10)));
int[] values = { 1 };
out("array: "+gson.toJson(values));
out("Deserialization");
int one = gson.fromJson("1", int.class);
out("one:"+one);
Integer intOne = gson.fromJson("1", Integer.class);
out("intOne:"+intOne);
Long longOne = gson.fromJson("1", Long.class);
out("longOne:"+longOne);
Boolean boolValue = gson.fromJson("false", Boolean.class);
out("boolValue:"+boolValue);
String str = gson.fromJson("\"abc\"", String.class);
out("str:"+str);
String anotherStr = gson.fromJson("[\"abc\"]", String.class);
out("anotherStr: "+anotherStr);
}
}