Skip to content

Commit

Permalink
[schema] use UTF_8 for storing schema information (apache#3666)
Browse files Browse the repository at this point in the history
*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
  • Loading branch information
sijie authored Feb 22, 2019
1 parent bd62dab commit 16bb6ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,7 +59,7 @@ private AvroSchema(org.apache.avro.Schema schema,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +65,7 @@ private JSONSchema(Class<T> pojo, Map<String, String> properties) {
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +74,7 @@ private ProtobufSchema(Map<String, String> properties, Class<T> pojo) {
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);
Expand Down

0 comments on commit 16bb6ce

Please sign in to comment.