Skip to content

Commit a4bdcef

Browse files
committed
Add a test (passing in 2.9, failin 2.10) for #2576
1 parent d33730c commit a4bdcef

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/test/java/com/fasterxml/jackson/databind/format/EnumFormatShapeTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.fasterxml.jackson.databind.format;
22

3+
import java.util.Collections;
4+
import java.util.Map;
5+
36
import com.fasterxml.jackson.annotation.*;
47
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
58

@@ -70,6 +73,24 @@ static class ColorWrapper {
7073
}
7174
}
7275

76+
// [databind#2576]
77+
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
78+
public enum Enum2576 {
79+
DEFAULT("default"),
80+
ATTRIBUTES("attributes") {
81+
@Override
82+
public String toString() {
83+
return name();
84+
}
85+
};
86+
87+
private final String key;
88+
private Enum2576(String key) {
89+
this.key = key;
90+
}
91+
public String getKey() { return this.key; }
92+
}
93+
7394
/*
7495
/**********************************************************
7596
/* Tests
@@ -113,4 +134,12 @@ public void testEnumPropertyAsNumber() throws Exception {
113134
assertEquals(String.format(aposToQuotes("{'color':%s}"), Color.GREEN.ordinal()),
114135
MAPPER.writeValueAsString(new ColorWrapper(Color.GREEN)));
115136
}
137+
138+
// [databind#2576]
139+
public void testEnumWithMethodOverride() throws Exception {
140+
String stringResult = MAPPER.writeValueAsString(Enum2576.ATTRIBUTES);
141+
Map<?,?> result = MAPPER.readValue(stringResult, Map.class);
142+
Map<String,String> exp = Collections.singletonMap("key", "attributes");
143+
assertEquals(exp, result);
144+
}
116145
}

0 commit comments

Comments
 (0)