jackson-databind: Exception thrown for incorrectly annotated record changed from `InvalidDefinitionException` to `MismatchedInputException`

Describe the bug

The exception thrown for an incorrectly annotated record has changed.

Version information 2.15.2

To Reproduce

Consider these two examples:

public record RecordWithSingleValueValue(@JsonValue String value) {}

public record RecordWithSingleValueCreatorDelegating(String value) {

  @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
  public RecordWithSingleValueCreatorDelegating {}

}

public class JacksonSerializationTest {

  private static final ObjectMapper mapper = new ObjectMapper();

  @Test
  public void recordWithSingleValueValue() throws JsonProcessingException {
    var instance = new RecordWithSingleValueValue("foo");
    var result = mapper.writeValueAsString(instance);
    assertEquals("\"foo\"", result);
    // missing setter
    assertThrows(InvalidDefinitionException.class,
        () -> mapper.readValue(result, RecordWithSingleValue.class));
  }

  @Test
  public void recordWithSingleValueCreatorDelegating() throws JsonProcessingException {
    var instance = new RecordWithSingleValueCreatorDelegating("foo");
    var result = mapper.writeValueAsString(instance);
    assertEquals("{\"value\":\"foo\"}", result);
    // missing setter
    assertThrows(InvalidDefinitionException.class,
        () -> mapper.readValue(result, RecordWithSingleValueCreatorDelegating.class));
  }
}

Expected behavior In 2.14.2 InvalidDefinitionException was thrown as shown above, with 2.15.3 this changed to MismatchedInputException. From my understanding InvalidDefinitionException was perhaps more “correct”?

Additional context I tried to figure out whether this change was intentional or not, but couldn’t find anything in the changelog or issues. I just wanted to let you know of this change – apologies if this was intentional and I missed it.

(I also found some other behavioral changes in 2.15, but I assume they are intentional – things that weren’t deserializing before are now deserializing.)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (12 by maintainers)

Most upvoted comments

This is closed issue, fwtw.

@Mochis Read my note above. If you have remaining problem case that is not covered by an open issue, please file a new, targeted issue for specific problem.

I added the reproduction for

Invalid type definition for type …Dto: Argument https://github.com/FasterXML/jackson-databind/pull/5 of constructor [constructor for …Dto (6 args), annotations: [null] has no property name annotation; must have name when multiple-parameter constructor annotated as Creator

in a second commit in the same repo.

It appears as if Jackson behaves wildly different with and without a Java module-info file, even on 2.14.2. I believe this should not be the case.

2.14.2 with module-info: jackson-2 14 2-with-module-info

2.14.2 without module-info: jackson-2 14 2-without-module-info

2.15.2 with module-info: jackson-2 15 2-with-module-info

2.15.2 without module-info: jackson-2 15 2-without-module-info

I’m not sure it makes sense to look at the behavioral changes between 2.14 and 2.15, if using the Java module system makes the results diverge that much.

Reproduction: https://github.com/soc/jackson-repro