org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor Maven / Gradle / Ivy
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or .
*/
package org.hibernate.type.descriptor.java;
import org.hibernate.type.descriptor.WrapperOptions;
/**
* Describes a Java Enum type.
*
* @author Steve Ebersole
*/
public class EnumJavaTypeDescriptor extends AbstractTypeDescriptor {
@SuppressWarnings("unchecked")
protected EnumJavaTypeDescriptor(Class type) {
super( type, ImmutableMutabilityPlan.INSTANCE );
JavaTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
}
@Override
public String toString(T value) {
return value == null ? "" : value.name();
}
@Override
public T fromString(String string) {
return string == null ? null : (T) Enum.valueOf( getJavaTypeClass(), string );
}
@Override
@SuppressWarnings("unchecked")
public X unwrap(T value, Class type, WrapperOptions options) {
return (X) value;
}
@Override
@SuppressWarnings("unchecked")
public T wrap(X value, WrapperOptions options) {
return (T) value;
}
}