Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.fasterxml.jackson.databind.deser.enums;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

public class EnumDeserializer5271Test
{
public enum MyEnum {
T10("10%"), T20("20%"), T30("30%");

private final String code;

MyEnum(String code) {
this.code = code;
}

@JsonValue
public String getCode() {
return code;
}
}

@Test
void convertStringToEnum() {
_testConvert(JsonMapper.builder().disable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.build()
);
Comment on lines +30 to +32

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one would pass since DeserializationFeature.READ_ENUMS_USING_TO_STRING is default behavior.

_testConvert(JsonMapper.builder().enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
.build()
);
}

private void _testConvert(JsonMapper mapper) {
assertThat(mapper.convertValue("10%", MyEnum.class))
.isEqualTo(MyEnum.T10);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public void testCustomEnumMapKeySerializer() throws Exception {
public void testJsonValueForEnumMapKey() throws Exception {
assertEquals(a2q("{'stuff':{'longValue':'foo'}}"),
MAPPER.writeValueAsString(new MyStuff594("foo")));
MyStuff594 ff = MAPPER.readValue(a2q("{'stuff':{'longValue':'foo'}}"), MyStuff594.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I merged this separately; fails in 3.0 as expected, passes on 2.18 - 2.20

System.out.println();
}

// [databind#2129]
Expand Down
Loading