/** * Whereas regular Enum serializer uses enum names, some users prefer calling toString() instead. * So let's verify that this can be done using annotation for enum class. */ public void testEnumUsingToString() throws Exception { StringWriter sw = new StringWriter(); mapper.writeValue(sw, AnnotatedTestEnum.C2); assertEquals("\"c2\"", sw.toString()); }
@SuppressWarnings("unchecked") private Map<String, Object> writeAndMap(ObjectMapper m, Object value) throws IOException { StringWriter sw = new StringWriter(); m.writeValue(sw, value); return (Map<String, Object>) m.readValue(sw.toString(), Object.class); }
public void testEnumSet() throws Exception { StringWriter sw = new StringWriter(); EnumSet<TestEnum> value = EnumSet.of(TestEnum.B); mapper.writeValue(sw, value); assertEquals("[\"B\"]", sw.toString()); }