-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Mismatch between scalar JSON type, creators, should give InputMismatchException
#1404
Comments
Slight regression: Expecting the following test to pass @Test
public void shouldBeInvalidDefinitionException() throws IOException {
final ObjectReader reader = new ObjectMapper().readerFor(BrokenRepresentation.class);
assertThatThrownBy(() -> reader.readValue("[\"hello\"]"))
.isInstanceOf(InvalidDefinitionException.class);
}
public class BrokenRepresentation {
private List<String> messages;
public BrokenRepresentation(List<String> messages) {
this.messages = messages;
}
@JsonProperty
public List<String> getMessages() {
return messages;
}
@JsonProperty
public void setMessages(List<String> messages) {
this.messages = messages;
}
} stacktrace
|
Hmmh. This is bit difficult.... I guess it is definition problem, in that there is no way to really instantiate it. |
My thought process, at a high level, is:
Of course, devil is in the details 😈 |
@nickbabcock Agreed with semantics. One thing, however, that I have found that adds another wrinkle is that often times it is better to defer failure. In this case, for example, just because a type can not be deserialized (due to lack of creator(s)), exception probably should not be thrown until an instance would be needed -- not right away during resolution of types. The reason I think deferring is preferred by users is based on past experiences: while I personally prefer early failure, there are often cases where theoretical problem is not practical one. This occurs -- for example -- when information is first collected, but then later on some is discarded. For example a property with a value of non-instantiatable type is Anyway: that's a lengthy explanation on how early to report the problem. I agree in that problem ought to be reported appropriately when it is necessary. |
@nickbabcock Implemented #1414, see if this improves handling, and what issues remain. |
I can confirm that your changes work 👏 No issues as of now |
(follow-up from #1356)
With current 2.9.0-SNAPSHOT, getting a JSON value like
boolean
, when there's no matching delegating creator, results inInvalidDefinitionException
. Should beInputMismatchException
.The text was updated successfully, but these errors were encountered: