|
|
@ -15,7 +15,6 @@ |
|
|
*/ |
|
|
*/ |
|
|
package org.thingsboard.server.transport.mqtt.adaptors; |
|
|
package org.thingsboard.server.transport.mqtt.adaptors; |
|
|
|
|
|
|
|
|
import com.google.gson.Gson; |
|
|
|
|
|
import com.google.gson.JsonElement; |
|
|
import com.google.gson.JsonElement; |
|
|
import com.google.gson.JsonObject; |
|
|
import com.google.gson.JsonObject; |
|
|
import com.google.gson.JsonParser; |
|
|
import com.google.gson.JsonParser; |
|
|
@ -56,8 +55,6 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { |
|
|
|
|
|
|
|
|
protected static final Charset UTF8 = StandardCharsets.UTF_8; |
|
|
protected static final Charset UTF8 = StandardCharsets.UTF_8; |
|
|
|
|
|
|
|
|
private static final Gson GSON = new Gson(); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public TransportProtos.PostTelemetryMsg convertToPostTelemetry(MqttDeviceAwareSessionContext ctx, MqttPublishMessage inbound) throws AdaptorException { |
|
|
public TransportProtos.PostTelemetryMsg convertToPostTelemetry(MqttDeviceAwareSessionContext ctx, MqttPublishMessage inbound) throws AdaptorException { |
|
|
String payload = validatePayload(ctx.getSessionId(), inbound.payload(), false); |
|
|
String payload = validatePayload(ctx.getSessionId(), inbound.payload(), false); |
|
|
@ -246,7 +243,7 @@ public class JsonMqttAdaptor implements MqttTransportAdaptor { |
|
|
new MqttFixedHeader(MqttMessageType.PUBLISH, false, ctx.getQoSForTopic(topic), false, 0); |
|
|
new MqttFixedHeader(MqttMessageType.PUBLISH, false, ctx.getQoSForTopic(topic), false, 0); |
|
|
MqttPublishVariableHeader header = new MqttPublishVariableHeader(topic, ctx.nextMsgId()); |
|
|
MqttPublishVariableHeader header = new MqttPublishVariableHeader(topic, ctx.nextMsgId()); |
|
|
ByteBuf payload = ALLOCATOR.buffer(); |
|
|
ByteBuf payload = ALLOCATOR.buffer(); |
|
|
payload.writeBytes(GSON.toJson(json).getBytes(UTF8)); |
|
|
payload.writeBytes(json.toString().getBytes(UTF8)); |
|
|
return new MqttPublishMessage(mqttFixedHeader, header, payload); |
|
|
return new MqttPublishMessage(mqttFixedHeader, header, payload); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|