philipnee commented on code in PR #12545:
URL: https://github.com/apache/kafka/pull/12545#discussion_r978832019
##########
clients/src/main/java/org/apache/kafka/common/serialization/StringDeserializer.java:
##########
@@ -27,27 +30,45 @@
* value.deserializer.encoding or deserializer.encoding. The first two take
precedence over the last.
*/
public class StringDeserializer implements Deserializer<String> {
+
private String encoding = StandardCharsets.UTF_8.name();
@Override
public void configure(Map<String, ?> configs, boolean isKey) {
- String propertyName = isKey ? "key.deserializer.encoding" :
"value.deserializer.encoding";
+ final String propertyName = isKey ? "key.deserializer.encoding" :
"value.deserializer.encoding";
Object encodingValue = configs.get(propertyName);
- if (encodingValue == null)
+ if (encodingValue == null) {
encodingValue = configs.get("deserializer.encoding");
- if (encodingValue instanceof String)
+ }
+
+ if (encodingValue instanceof String) {
encoding = (String) encodingValue;
+ }
}
@Override
public String deserialize(String topic, byte[] data) {
try {
- if (data == null)
- return null;
- else
- return new String(data, encoding);
+ return data == null ? null : new String(data, encoding);
} catch (UnsupportedEncodingException e) {
throw new SerializationException("Error when deserializing byte[]
to string due to unsupported encoding " + encoding);
}
}
+
+ @Override
+ public String deserialize(String topic, Headers headers, ByteBuffer data) {
+ if (data == null) {
+ return null;
+ }
+
+ try {
+ if (data.hasArray()) {
+ return new String(data.array(), data.position() +
data.arrayOffset(), data.remaining(), encoding);
+ } else {
Review Comment:
exactly.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]