You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by si...@apache.org on 2019/02/22 15:28:06 UTC
[pulsar] branch master updated: [schema] use UTF_8 for storing
schema information (#3666)
This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 16bb6ce [schema] use UTF_8 for storing schema information (#3666)
16bb6ce is described below
commit 16bb6ce71d21356839d2e14c2de6aeb9bc6d6d57
Author: Sijie Guo <gu...@gmail.com>
AuthorDate: Fri Feb 22 23:27:59 2019 +0800
[schema] use UTF_8 for storing schema information (#3666)
*Motivation*
Currently we don't specify charset. It will be causing troubles when client
and broker are using different system charsets.
*Modifications*
Use UTF_8 for the schema information for AVRO/PROTOBUF/JSON
---
.../main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java | 4 +++-
.../main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java | 4 +++-
.../java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java | 4 +++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
index 2680b3a..c7e4a93 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/AvroSchema.java
@@ -18,6 +18,8 @@
*/
package org.apache.pulsar.client.impl.schema;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import lombok.extern.slf4j.Slf4j;
import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.BinaryEncoder;
@@ -57,7 +59,7 @@ public class AvroSchema<T> implements Schema<T> {
this.schemaInfo.setName("");
this.schemaInfo.setProperties(properties);
this.schemaInfo.setType(SchemaType.AVRO);
- this.schemaInfo.setSchema(this.schema.toString().getBytes());
+ this.schemaInfo.setSchema(this.schema.toString().getBytes(UTF_8));
this.byteArrayOutputStream = new ByteArrayOutputStream();
this.encoder = EncoderFactory.get().binaryEncoder(this.byteArrayOutputStream, this.encoder);
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java
index dbcc489..3289584 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/JSONSchema.java
@@ -18,6 +18,8 @@
*/
package org.apache.pulsar.client.impl.schema;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -63,7 +65,7 @@ public class JSONSchema<T> implements Schema<T>{
this.schemaInfo.setName("");
this.schemaInfo.setProperties(properties);
this.schemaInfo.setType(SchemaType.JSON);
- this.schemaInfo.setSchema(this.schema.toString().getBytes());
+ this.schemaInfo.setSchema(this.schema.toString().getBytes(UTF_8));
this.objectMapper = JSON_MAPPER.get();
}
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java
index 34ec46b..c7524e9 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/ProtobufSchema.java
@@ -18,6 +18,8 @@
*/
package org.apache.pulsar.client.impl.schema;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.protobuf.Descriptors;
@@ -72,7 +74,7 @@ public class ProtobufSchema<T extends com.google.protobuf.GeneratedMessageV3> im
this.schemaInfo.setType(SchemaType.PROTOBUF);
ProtobufDatumReader datumReader = new ProtobufDatumReader(pojo);
org.apache.avro.Schema schema = datumReader.getSchema();
- this.schemaInfo.setSchema(schema.toString().getBytes());
+ this.schemaInfo.setSchema(schema.toString().getBytes(UTF_8));
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalArgumentException(e);