com.ibm.wiotp.sdk.codecs

Class JsonCodec

  • All Implemented Interfaces:
    MessageCodec<com.google.gson.JsonObject>


    public class JsonCodec
    extends Object
    implements MessageCodec<com.google.gson.JsonObject>
    • Constructor Detail

      • JsonCodec

        public JsonCodec()
    • Method Detail

      • encode

        public byte[] encode(com.google.gson.JsonObject data,
                             org.joda.time.DateTime timestamp)
        Description copied from interface: MessageCodec
        Convert an Object into a byte array suitable to send via MQTT
        Specified by:
        encode in interface MessageCodec<com.google.gson.JsonObject>
        Parameters:
        data - the Object to be encoded
        timestamp - the time that the message was generated
        Returns:
        Byte array ready for MQTT message payload
      • decode

        public JsonMessage decode(org.eclipse.paho.client.mqttv3.MqttMessage msg)
                           throws MalformedMessageException
        Description copied from interface: MessageCodec
        Convert an MQTT message into an instance of com.ibm.wiotp.sdk.Message
        Specified by:
        decode in interface MessageCodec<com.google.gson.JsonObject>
        Parameters:
        msg - the MqttMessage from Paho MQTT client to decode
        Returns:
        Object of class T from the decoded MQTT message
        Throws:
        MalformedMessageException - If unable to decode the message
      • getMessageClass

        public Class<com.google.gson.JsonObject> getMessageClass()
        Specified by:
        getMessageClass in interface MessageCodec<com.google.gson.JsonObject>

Copyright © 2019. All rights reserved.