12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package com.yiidata.intergration.web.modules.sys.cache.serde;
- import java.nio.charset.Charset;
- import java.nio.charset.StandardCharsets;
- /**
- * <pre>
- *
- * Created by zhaopx.
- * User: zhaopx
- * Date: 2019/11/14
- * Time: 11:47
- *
- * </pre>
- *
- * @author zhaopx
- */
- public class StringSerializer implements Serializer<String> {
- /**
- * 默认的编码
- */
- 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);
- }
- }
|