Merge pull request #5792 from ViacheslavKlimov/fix/mqtt-attr-encoding

[3.3.3] Fix invalid serialization of '=' to \u003d in JsonMqttAdaptor
This commit is contained in:
Andrew Shvayka 2021-12-29 12:22:05 +02:00 committed by GitHub
commit c77a5d055d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
} }