package com.yiidata.intergration.web.modules.sys.cache.serde;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
/**
*
*
* Created by zhaopx.
* User: zhaopx
* Date: 2019/11/14
* Time: 11:47
*
*
*
* @author zhaopx
*/
public class StringSerializer implements Serializer {
/**
* 默认的编码
*/
final Charset defaultCharset;
public StringSerializer() {
this(StandardCharsets.UTF_8);
}
public StringSerializer(Charset charset) {
this.defaultCharset = charset;
}
@Override
public byte[] serialize(String s) {
return s.getBytes(defaultCharset);
}
@Override
public String deserialize(byte[] bytes) {
return new String(bytes);
}
}