@Test public void testStringToEnumConversion() throws Exception { assertEquals( Seasons.SUMMER, converter.convert(Seasons.class, "SUMMER"), "Enum converter correctly converted String to enum"); assertEquals( Seasons.FALL, converter.convert(Seasons.class, "FALL"), "Enum converter correctly converted String to enum"); }
@Override public <T> T convert(Class<T> cls, Object value) { try { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return stringToEnum(cls, (String) value); } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { return intToEnum(cls, (Integer) value); } else { throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } } catch (IndexOutOfBoundsException | ReflectiveOperationException | UnsupportedOperationException | IllegalArgumentException e) { throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e); } }
ToEnumConverter implements Converter { @Override public <T> T convert(Class<T> cls, Object value) { try { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return stringToEnum(cls, (String) value); } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { return intToEnum(cls, (Integer) value); } else { throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } } catch (IndexOutOfBoundsException | ReflectiveOperationException | UnsupportedOperationException | IllegalArgumentException e) { throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e); } } }
ToEnumConverter implements Converter { @Override public <T> T convert(Class<T> cls, Object value) { try { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return stringToEnum(cls, (String) value); } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { return intToEnum(cls, (Integer) value); } else { throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } } catch (IndexOutOfBoundsException | ReflectiveOperationException | UnsupportedOperationException | IllegalArgumentException e) { throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e); } }  }
ToEnumConverter implements Converter { @Override public <T> T convert(Class<T> cls, Object value) { try { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return stringToEnum(cls, (String) value); } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { return intToEnum(cls, (Integer) value); } else { throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } } catch (IndexOutOfBoundsException | ReflectiveOperationException | UnsupportedOperationException | IllegalArgumentException e) { throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e); } }  @Override T convert(Class<T> cls, Object value); }
ToEnumConverter implements Converter { @Override public <T> T convert(Class<T> cls, Object value) { try { if (ClassUtils.isAssignable(value.getClass(), String.class)) { return stringToEnum(cls, (String) value); } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) { return intToEnum(cls, (Integer) value); } else { throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported"); } } catch (IndexOutOfBoundsException | ReflectiveOperationException | UnsupportedOperationException | IllegalArgumentException e) { throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e); } }  @Override T convert(Class<T> cls, Object value);  }