-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc6a1ae
commit 2aa21dd
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/test/java/com/fasterxml/jackson/databind/deser/enums/EnumSameName4302Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.fasterxml.jackson.databind.deser.enums; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import static com.fasterxml.jackson.databind.BaseMapTest.jsonMapperBuilder; | ||
import static com.fasterxml.jackson.databind.BaseTest.q; | ||
|
||
// [databind#4302] | ||
public class EnumSameName4302Test | ||
{ | ||
|
||
enum Field4302Enum { | ||
FOO(0); | ||
|
||
public final int foo; | ||
|
||
Field4302Enum(int foo) { | ||
this.foo = foo; | ||
} | ||
} | ||
|
||
enum Getter4302Enum { | ||
BAR("bar"); | ||
|
||
public String bar; | ||
|
||
Getter4302Enum(String bar) { | ||
this.bar = bar; | ||
} | ||
|
||
public String getBar() { | ||
return "bar"; | ||
} | ||
} | ||
|
||
enum Setter4302Enum { | ||
CAT("dog"); | ||
|
||
public String cat; | ||
|
||
Setter4302Enum(String cat) { | ||
this.cat = cat; | ||
} | ||
|
||
public void setCat(String cat) { | ||
this.cat = cat; | ||
} | ||
} | ||
|
||
private final ObjectMapper MAPPER = jsonMapperBuilder() | ||
.propertyNamingStrategy(PropertyNamingStrategies.LOWER_CASE) | ||
.build(); | ||
|
||
@Test | ||
void testShouldWork() throws Exception | ||
{ | ||
// First, try roundtrip with same-ignore-case name field | ||
assertEquals(Field4302Enum.FOO, | ||
MAPPER.readValue("\"FOO\"", Field4302Enum.class)); | ||
assertEquals(q("FOO"), | ||
MAPPER.writeValueAsString(Field4302Enum.FOO)); | ||
|
||
// Now, try roundtrip with same-ignore-case name getter | ||
assertEquals(Getter4302Enum.BAR, | ||
MAPPER.readValue("\"BAR\"", Getter4302Enum.class)); | ||
assertEquals(q("BAR"), | ||
MAPPER.writeValueAsString(Getter4302Enum.BAR)); | ||
|
||
// Now, try roundtrip with same-ignore-case name setter | ||
Setter4302Enum.CAT.setCat("cat"); | ||
assertEquals(Setter4302Enum.CAT, | ||
MAPPER.readValue("\"CAT\"", Setter4302Enum.class)); | ||
assertEquals(q("CAT"), | ||
MAPPER.writeValueAsString(Setter4302Enum.CAT)); | ||
} | ||
} | ||
|