All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.vpro.persistence.StringListConverter Maven / Gradle / Ivy

The newest version!
package nl.vpro.persistence;


import java.util.Arrays;
import java.util.List;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;

/**
 * @author Michiel Meeuwissen
 * @since 2.8
 */
@Converter
public class StringListConverter implements AttributeConverter, String> {

    public static final StringListConverter INSTANCE = new StringListConverter();

    private static final String SPLIT_CHAR = "\t";

    @Override
    public String convertToDatabaseColumn(List stringList) {
        if (stringList == null || stringList.isEmpty()) {
            return null;
        }
        return String.join(SPLIT_CHAR, stringList);
    }

    @Override
    public List convertToEntityAttribute(String string) {
        if (string == null || string.isEmpty()) {
            return null;
        }
        return Arrays.asList(string.split(SPLIT_CHAR));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy