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

org.simpleflatmapper.converter.impl.ObjectToEnumConverter Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.converter.impl;

import org.simpleflatmapper.converter.Converter;
import org.simpleflatmapper.util.EnumHelper;

public class ObjectToEnumConverter> implements Converter {
    private final Class enumClass;

    private final NumberToEnumConverter numberToEnumConverter;

    public ObjectToEnumConverter(Class enumClass) {
        this.enumClass = enumClass;
        this.numberToEnumConverter = new NumberToEnumConverter(enumClass);
    }

    @Override
    public E convert(Object in) throws Exception {
        if (in == null) return null;
        if (in instanceof Number) {
            return numberToEnumConverter.convert((Number) in);
        } else {
            return Enum.valueOf(enumClass, String.valueOf(in));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy