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

io.rocketbase.commons.model.converter.StringListConverter Maven / Gradle / Ivy

There is a newer version: 4.4.1
Show newest version
package io.rocketbase.commons.model.converter;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import org.springframework.util.StringUtils;

import javax.persistence.AttributeConverter;
import javax.persistence.Convert;
import java.util.ArrayList;
import java.util.List;

@Convert
public class StringListConverter implements AttributeConverter, String> {

    @Override
    public String convertToDatabaseColumn(List attribute) {
        String result = null;
        if (attribute != null) {
            result = Joiner.on(";").join(attribute);
        }
        return result;
    }

    @Override
    public List convertToEntityAttribute(String dbData) {
        List result = new ArrayList<>();
        if (!StringUtils.isEmpty(dbData)) {
            result = Lists.newArrayList(Splitter.on(";").split(dbData));
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy