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

org.minijax.db.StringListConverter Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
package org.minijax.db;

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

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter
public class StringListConverter implements AttributeConverter, String> {

    @Override
    public String convertToDatabaseColumn(final List list) {
        if (list == null) {
            return "";
        }
        return String.join(",", list);
    }

    @Override
    public List convertToEntityAttribute(final String joined) {
        if (joined == null) {
            return new ArrayList<>();
        }
        return new ArrayList<>(Arrays.asList(joined.split(",")));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy