-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bd5d3d6
commit 45b2dac
Showing
2 changed files
with
97 additions
and
34 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
71 changes: 71 additions & 0 deletions
71
...l/jackson/databind/ser/enums/WriteEnumsToLowerCaseOverridesJsonPropertyValue4788Test.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,71 @@ | ||
package com.fasterxml.jackson.databind.ser.enums; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.EnumNamingStrategies; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.annotation.EnumNaming; | ||
import com.fasterxml.jackson.databind.cfg.EnumFeature; | ||
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
// [databind#4788] 2.18 | ||
public class WriteEnumsToLowerCaseOverridesJsonPropertyValue4788Test | ||
extends DatabindTestUtil | ||
{ | ||
|
||
public enum SauceA { | ||
@JsonProperty("Ketchup") | ||
KETCHUP, | ||
} | ||
|
||
@EnumNaming(EnumNamingStrategies.CamelCaseStrategy.class) | ||
public enum SauceB { | ||
@JsonProperty("PROPERTY_MAYO_NAIZZZZ") | ||
MAYO_NAIZZZZ | ||
} | ||
|
||
public enum SauceC { | ||
@JsonProperty("Is-A-Prop") | ||
IS_MY_NAME | ||
} | ||
|
||
ObjectMapper objectMapper = jsonMapperBuilder() | ||
.configure(EnumFeature.WRITE_ENUMS_TO_LOWERCASE, true) | ||
.build(); | ||
|
||
@Test | ||
void shouldUseJsonPropertySimple() | ||
throws Exception | ||
{ | ||
assertEquals( | ||
"\"Ketchup\"", | ||
objectMapper.writeValueAsString(SauceA.KETCHUP) | ||
); | ||
|
||
} | ||
|
||
@Test | ||
void shouldUseJsonPropertyOverEnumNaming() | ||
throws Exception | ||
{ | ||
assertEquals( | ||
"\"PROPERTY_MAYO_NAIZZZZ\"", | ||
objectMapper.writeValueAsString(SauceB.MAYO_NAIZZZZ) | ||
); | ||
} | ||
|
||
@Test | ||
void shouldUseJsonPropertyOverToString() | ||
throws Exception | ||
{ | ||
assertEquals( | ||
"\"Is-A-Prop\"", | ||
objectMapper.writer().with(SerializationFeature.WRITE_ENUMS_USING_TO_STRING) | ||
.writeValueAsString(SauceC.IS_MY_NAME) | ||
); | ||
} | ||
} |