+ /**
+ * Prepare json from notification data
+ *
+ * @return json as {@link String}
+ */
+ private String prepareJson() {
+ final JSONObject json = new JSONObject();
+ json.put("ietf-restconf:notification",
+ new JSONObject(writeBodyToString()).put("event-time", ListenerAdapter.toRFC3339(new Date())));
+ return json.toString();
+ }
+
+ private String writeBodyToString() {
+ final Writer writer = new StringWriter();
+ final NormalizedNodeStreamWriter jsonStream =
+ JSONNormalizedNodeStreamWriter.createExclusiveWriter(JSONCodecFactory.create(this.schemaContext),
+ this.notification.getType(), null, JsonWriterFactory.createJsonWriter(writer));
+ final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream);
+ try {
+ nodeWriter.write(this.notification.getBody());
+ nodeWriter.close();
+ } catch (final IOException e) {
+ throw new RestconfDocumentedException("Problem while writing body of notification to JSON. ", e);
+ }
+ return writer.toString();
+ }
+