+ public JsonReceiveMessageHandler(Manager m) {
+ this.m = m;
+ this.jsonProcessor = new ObjectMapper();
+ jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); // disable autodetect
+ jsonProcessor.enable(SerializationFeature.WRITE_NULL_MAP_VALUES);
+ jsonProcessor.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
+ }
+
+ @Override
+ public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) {
+ ObjectNode result = jsonProcessor.createObjectNode();
+ if (exception != null) {
+ result.putPOJO("error", new JsonError(exception));
+ }
+ if (envelope != null) {
+ result.putPOJO("envelope", new JsonMessageEnvelope(envelope, content));
+ }
+ try {
+ jsonProcessor.writeValue(System.out, result);
+ System.out.println();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }