|
@@ -60,6 +60,23 @@ public class SessionAnswers implements Jsonable {
|
60
|
60
|
// ------------------------------------------------------------------
|
61
|
61
|
// Jsonable Implementation
|
62
|
62
|
// ------------------------------------------------------------------
|
|
63
|
+ public JsonObject asJsonObject()
|
|
64
|
+ {
|
|
65
|
+ JsonObject vResult = new JsonObject();
|
|
66
|
+ JsonArray vAnswers = new JsonArray();
|
|
67
|
+ fAnswers.forEach( (question, answer) -> {
|
|
68
|
+ vAnswers.add(answer.asJsonObject().putChain(KEY_QUESTION, question.asJsonObject()));
|
|
69
|
+ });
|
|
70
|
+ vResult.put(KEY_ANSWERS, vAnswers);
|
|
71
|
+ JsonArray vTraits = new JsonArray();
|
|
72
|
+ fTraits.forEach( (trait, weight) -> {
|
|
73
|
+ vTraits.add(trait.asJsonObject().putChain(KEY_WEIGHT, weight));
|
|
74
|
+ });
|
|
75
|
+ vResult.put(KEY_TRAITS, vTraits);
|
|
76
|
+ return vResult;
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+
|
63
|
80
|
@Override
|
64
|
81
|
public String toJson() {
|
65
|
82
|
final StringWriter writable = new StringWriter();
|
|
@@ -74,18 +91,7 @@ public class SessionAnswers implements Jsonable {
|
74
|
91
|
|
75
|
92
|
@Override
|
76
|
93
|
public void toJson(Writer writable) throws IOException {
|
77
|
|
- JsonObject vResult = new JsonObject();
|
78
|
|
- JsonArray vAnswers = new JsonArray();
|
79
|
|
- fAnswers.forEach( (question, answer) -> {
|
80
|
|
- vAnswers.add(answer.asJsonObject().putChain(KEY_QUESTION, question.asJsonObject()));
|
81
|
|
- });
|
82
|
|
- vResult.put(KEY_ANSWERS, vAnswers);
|
83
|
|
- JsonArray vTraits = new JsonArray();
|
84
|
|
- fTraits.forEach( (trait, weight) -> {
|
85
|
|
- vTraits.add(trait.asJsonObject().putChain(KEY_WEIGHT, weight));
|
86
|
|
- });
|
87
|
|
- vResult.put(KEY_TRAITS, vTraits);
|
88
|
|
- writable.write(new String(vResult.toJson().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
|
|
94
|
+ writable.write(new String(asJsonObject().toJson().getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
|
89
|
95
|
}
|
90
|
96
|
|
91
|
97
|
}
|