Skip to content

Add failing test for #5210 #5213

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

Closed
wants to merge 1 commit into from
Closed
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,60 @@
package com.fasterxml.jackson.databind.tofix;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.cfg.ConstructorDetector;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.testutil.failure.JacksonTestFailureExpected;

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

public class ConstructorDetector5210Test {

// succeeds with 2.12.7
// also succeeds with 2.17.0, 2.17.2, 2.18.0, 2.18.1, 2.18.2
// fails with 2.18.3+
@JacksonTestFailureExpected
@Test
public void testSerialization() throws JsonProcessingException {
String json = "{\"someFiled\":\"imSomeStringVal\"}";

ObjectMapper objectMapper = JsonMapper.builder()
.constructorDetector(ConstructorDetector.USE_PROPERTIES_BASED)
.build();

// no exception starting from 2.18.3
assertThrows(JsonMappingException.class, () -> {
objectMapper.readValue(json, WrapperClass.class);
});
}

public static class WrapperClass {
@JsonProperty("someFiled")
private final SingleStringClass someFiled;

private WrapperClass() {
someFiled = null;
}

public WrapperClass(SingleStringClass someFiled) {
this.someFiled = someFiled;
}
}

public static class SingleStringClass {
@JsonProperty("someStringVal")
private final String someStringVal;

private SingleStringClass() {
someStringVal = null;
}

public SingleStringClass(String someStringVal) {
this.someStringVal = someStringVal;
}
}
}