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

fr.fezlight.eventsystem.converters.ClassConverters Maven / Gradle / Ivy

The newest version!
package fr.fezlight.eventsystem.converters;

import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.convert.WritingConverter;

/**
 * Class used to convert {@link Class} object into MongoDB.
 *
 * @author FezLight
 */
public class ClassConverters {
    @ReadingConverter
    public static class ClassReadConverter implements Converter> {
        @Override
        public Class convert(String source) {
            try {
                return Class.forName(source);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }
    }

    @WritingConverter
    public static class ClassWriteConverter implements Converter, String> {
        @Override
        public String convert(Class source) {
            return source.getName();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy