Skip to content

Commit

Permalink
test : new regression against 2.18
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim committed Nov 11, 2024
1 parent d1a8e71 commit 69334dd
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.fasterxml.jackson.databind.tofix;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

import static com.fasterxml.jackson.annotation.JsonProperty.Access.READ_ONLY;

// [databind#4792] JsonUnwrapped throwing "Unrecognized field" after upgrade to 2.18
public class PolymorphicDeserWithJsonUnwrapped4792Test
extends DatabindTestUtil
{

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "name")
@JsonSubTypes({
@JsonSubTypes.Type(value = SubA.class, name = "A"),
})
interface Parent { }

static class SubA implements Parent {
@JsonUnwrapped
@JsonProperty(access = READ_ONLY)
private Model model;

@JsonCreator
public SubA(@JsonProperty("model") Model model) {
this.model = model;
}
}

static class Model {
public String name;
}

public static class Wrapper {
public Parent model;
}

private final ObjectMapper objectMapper = newJsonMapper();

@JacksonTestFailureExpected
@Test
public void testMainTest()
throws Exception
{
Wrapper w = objectMapper.readValue(a2q("{'model':{'name':'A','name': 'Rick'}}"), Wrapper.class);

assertInstanceOf(SubA.class, w.model);
assertInstanceOf(Model.class, ((SubA) w.model).model);
assertEquals("Rick", ((SubA) w.model).model.name);
}

}

0 comments on commit 69334dd

Please sign in to comment.