-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonObject.java
34 lines (28 loc) · 1.04 KB
/
JsonObject.java
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
package by.grodno.krivosheev.objects;
import by.grodno.krivosheev.core.AbstractObject;
import by.grodno.krivosheev.core.Parser;
import by.grodno.krivosheev.core.SyntaxException;
import by.grodno.krivosheev.core.Constants;
import java.util.stream.Collectors;
public class JsonObject extends AbstractObject {
public JsonObject() {
super();
}
/**
* Construct ObjectJSON
* @param source String JSON
* @throws SyntaxException If the {@code source} expression's syntax is invalid
*/
public JsonObject(String source) throws SyntaxException {
super(Parser.getJsonObject(source).getMap());
}
@Override
public String toString() {
if (this.isEmpty()) return null;
return this.getMap().keySet().stream()
.map(key -> Constants.classes.contains(this.getObject(key).getClass()) ?
"\"" + key + "\":" + this.getObject(key) :
"\"" + key + "\":\"" + this.getObject(key) + "\"")
.collect(Collectors.joining(",", "{", "}"));
}
}