Skip to content

Commit

Permalink
Add failing test for #4403 (default enum read fail) (#4408)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Mar 3, 2024
1 parent 23f3b7a commit 9fb5b8d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ enum MixinOverloadedDefault {
/* Test methods
/**********************************************************
*/
private final ObjectMapper MAPPER = new ObjectMapper();

private final ObjectMapper MAPPER = newJsonMapper();

@Test
public void testWithoutCustomFeatures() throws Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.fasterxml.jackson.failing;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonEnumDefaultValue;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;

import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.newJsonMapper;
import static com.fasterxml.jackson.databind.testutil.DatabindTestUtil.q;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class EnumDefaultRead4403Test
{
// [databind#4403]
enum Brand4403 {
@JsonProperty("005")
SEAT,
@JsonProperty("006")
HYUNDAI,
@JsonEnumDefaultValue
OTHER
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = newJsonMapper();

// [databind#4403]
@Test
public void readFromDefault4403() throws Exception
{
ObjectReader r = MAPPER.readerFor(Brand4403.class)
.with(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE);
assertEquals(Brand4403.SEAT, r.readValue(q("005")));
assertEquals(Brand4403.HYUNDAI, r.readValue(q("006")));
assertEquals(Brand4403.OTHER, r.readValue(q("x")));

// Problem here: "001" taken as "Stringified" index 1
assertEquals(Brand4403.OTHER, r.readValue(q("001")));
}

}

0 comments on commit 9fb5b8d

Please sign in to comment.