zookeeperzkClient 客户端读取child节点数据报错,序列化问题。org.I0Itec.zkclient.exception.ZkMarshallingError: java.io.StreamCorruptedException: invalid stream header: 31302E31
zkClient = new ZkClient(new ZkConnection("127.0.0.1:2181"), 10000);
zkClient.setZkSerializer(new MyZkSerializer());
实现自己的序列化不要使用zkclient默认的
public class MyZkSerializer implements ZkSerializer {
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
try {
return new String(bytes, "utf-8");
} catch (final UnsupportedEncodingException e) {
throw new ZkMarshallingError(e);
}
}
public byte[] serialize(Object obj) throws ZkMarshallingError {
try {
return String.valueOf(obj).getBytes("UTF-8");
} catch (final UnsupportedEncodingException e) {
throw new ZkMarshallingError(e);
}
}
}