javax.persistence.StringToByteArrayUTF8Converter Maven / Gradle / Ivy
package javax.persistence;
import java.nio.charset.StandardCharsets;
/**
* @see java.nio.charset.Charset#defaultCharset()
*/
@Converter
public class StringToByteArrayUTF8Converter implements AttributeConverter {
@Override
public byte[] convertToDatabaseColumn(String attribute) {
if (attribute == null) {
return null;
}
return attribute.getBytes(StandardCharsets.UTF_8);
}
@Override
public String convertToEntityAttribute(byte[] dbData) {
if (dbData == null) {
return null;
}
return new String(dbData, StandardCharsets.UTF_8);
}
}