File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed
src/main/java/minimal_json Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <project xmlns =" http://maven.apache.org/POM/4.0.0"
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
5
+ <modelVersion >4.0.0</modelVersion >
6
+ <artifactId >minimal-json</artifactId >
7
+ <name >Json :: minimal-json</name >
8
+ <groupId >com.github.vedenin</groupId >
9
+ <version >0.01</version >
10
+
11
+ <dependencies >
12
+ <dependency >
13
+ <groupId >com.eclipsesource.minimal-json</groupId >
14
+ <artifactId >minimal-json</artifactId >
15
+ <version >0.9.4</version >
16
+ </dependency >
17
+ </dependencies >
18
+ </project >
Original file line number Diff line number Diff line change
1
+ package minimal_json ;
2
+
3
+
4
+ import com .eclipsesource .json .Json ;
5
+ import com .eclipsesource .json .JsonObject ;
6
+
7
+ import java .io .IOException ;
8
+ import java .io .StringWriter ;
9
+
10
+ /**
11
+ * Json-Java Hello World
12
+ */
13
+ public class JsonMinimalHelloWorld {
14
+
15
+ public static void main (String [] args ) throws IOException {
16
+ // convert Java to writer
17
+ JsonObject root = Json .object ().add ("message" , "Hi" ).add (
18
+ "place" , Json .object ().add ("name" , "World!" )
19
+ );
20
+ StringWriter writer = new StringWriter ();
21
+ root .writeTo (writer );
22
+ String json = writer .toString ();
23
+ System .out .println (json );
24
+
25
+ System .out .println ();
26
+ // convert writer to Java
27
+ JsonObject obj = Json .parse (json ).asObject ();
28
+ String message = obj .get ("message" ).asString ();
29
+ String name = obj .get ("place" ).asObject ().get ("name" ).asString ();
30
+ System .out .println (message + " " + name );
31
+ }
32
+ }
Original file line number Diff line number Diff line change 24
24
<module >genson</module >
25
25
<module >logansquare</module >
26
26
<module >json_simple</module >
27
+ <module >minimal-json</module >
27
28
</modules >
28
29
</project >
You can’t perform that action at this time.
0 commit comments