Skip to content

Commit

Permalink
test : Add tofix test case for FasterXML#4629
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim committed Dec 1, 2024
1 parent a185fbf commit ad19379
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.fasterxml.jackson.databind.tofix;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.testutil.DatabindTestUtil;
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;
import org.junit.jupiter.api.Test;

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

// [databind#4629] @JsonIncludeProperties & @JsonIgnoreProperties
// are ignored when deserializing Records
public class RecordsWithJsonIncludeAndIgnorals4629Test
extends DatabindTestUtil {

record Id2Name(
int id,
String name
) { }

record RecordWithInclude4629(
@JsonIncludeProperties("id") Id2Name child
) { }

record RecordWIthIgnore4629(
@JsonIgnoreProperties("name") Id2Name child
) { }

private final ObjectMapper MAPPER = newJsonMapper();

@JacksonTestFailureExpected
@Test
void testJsonInclude4629()
throws Exception
{
RecordWithInclude4629 expected = new RecordWithInclude4629(new Id2Name(123, null));
String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}";

RecordWithInclude4629 actual = MAPPER.readValue(input, RecordWithInclude4629.class);

assertEquals(expected, actual);
}

@JacksonTestFailureExpected
@Test
void testJsonIgnore4629()
throws Exception
{
RecordWIthIgnore4629 expected = new RecordWIthIgnore4629(new Id2Name(123, null));
String input = "{\"child\":{\"id\":123,\"name\":\"Bob\"}}";

RecordWIthIgnore4629 actual = MAPPER.readValue(input, RecordWIthIgnore4629.class);

assertEquals(expected, actual);
}

}

0 comments on commit ad19379

Please sign in to comment.