io.github.icodegarden.nutrient.lang.serialization.StringSerializer Maven / Gradle / Ivy
The newest version!
package io.github.icodegarden.nutrient.lang.serialization;
import java.io.UnsupportedEncodingException;
/**
*
* @author Fangfang.Xu
*
*/
public class StringSerializer implements Serializer {
private String encoding = "UTF8";
@Override
public byte[] serialize(String data) throws SerializationException {
try {
if (data == null)
return null;
else
return data.getBytes(encoding);
} catch (UnsupportedEncodingException e) {
throw new SerializationException(
"Error when serializing string to byte[] due to unsupported encoding " + encoding);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy