Skip to content

Commit 0b2ebbd

Browse files
author
vvedenin
committed
Add minimal_json to json sections
1 parent 63089c2 commit 0b2ebbd

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

helloworlds/3.8-json/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
<module>genson</module>
2525
<module>logansquare</module>
2626
<module>json_simple</module>
27+
<module>minimal-json</module>
2728
</modules>
2829
</project>

0 commit comments

Comments
 (0)