Skip to content

Commit 76539d7

Browse files
Durga, V H V SekharDurga, V H V Sekhar
Durga, V H V Sekhar
authored and
Durga, V H V Sekhar
committed
Added unit test for Issue-4214
1 parent be56569 commit 76539d7

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.databind.BaseMapTest;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
6+
import java.util.EnumSet;
7+
import java.util.Set;
8+
9+
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
10+
import com.fasterxml.jackson.annotation.PropertyAccessor;
11+
import com.fasterxml.jackson.databind.DeserializationFeature;
12+
import com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping;
13+
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
14+
15+
public class EnumSetSerializationTest extends BaseMapTest {
16+
17+
static enum MyEnum {
18+
ITEM_A, ITEM_B;
19+
}
20+
21+
static class EnumSetHolder {
22+
private Set<MyEnum> enumSet; // use Set instead of EnumSet for type of this
23+
24+
public Set<MyEnum> getEnumSet() {
25+
return enumSet;
26+
}
27+
28+
public void setEnumSet(Set<MyEnum> enumSet) {
29+
this.enumSet = enumSet;
30+
}
31+
32+
@Override
33+
public boolean equals(Object o) {
34+
if (!(o instanceof EnumSetHolder)) {
35+
return false;
36+
}
37+
EnumSetHolder eh = (EnumSetHolder) o;
38+
if (eh == this) {
39+
return true;
40+
}
41+
if (enumSet == null) {
42+
if (eh.getEnumSet() == null) {
43+
return true;
44+
} else {
45+
return false;
46+
}
47+
} else {
48+
if (eh.getEnumSet() == null) {
49+
return false;
50+
}
51+
return enumSet.containsAll(eh.getEnumSet());
52+
}
53+
}
54+
}
55+
56+
public void testSerialization() throws Exception {
57+
ObjectMapper mapper = jsonMapperBuilder().build()
58+
// this type information is needed in json string, for this test
59+
.activateDefaultTyping(BasicPolymorphicTypeValidator.builder().allowIfBaseType(Object.class).build(),
60+
DefaultTyping.EVERYTHING);
61+
62+
EnumSetHolder enumSetHolder = new EnumSetHolder();
63+
enumSetHolder.setEnumSet(EnumSet.allOf(MyEnum.class));
64+
String jsonStr = mapper.writeValueAsString(enumSetHolder);
65+
EnumSetHolder result = mapper.readValue(jsonStr, EnumSetHolder.class);
66+
assertEquals(result, enumSetHolder);
67+
}
68+
}

0 commit comments

Comments
 (0)