Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test : Add tofix test case for #4629 #4823

Merged
merged 1 commit into from
Dec 1, 2024
Merged
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,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);
}

}