@Override public void messageArrived(String topic, MqttMessage message) throws Exception { Topic sparkplugTopic = TopicUtil.parseTopic(topic); ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); System.out.println("Message Arrived on Sparkplug topic " + sparkplugTopic.toString()); SparkplugBPayloadDecoder decoder = new SparkplugBPayloadDecoder(); SparkplugBPayload inboundPayload = decoder.buildFromByteArray(message.getPayload()); // Convert the message to JSON and print to system.out try { String payloadString = mapper.writeValueAsString(inboundPayload); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inboundPayload)); } catch (Exception e) { e.printStackTrace(); } }