-
Notifications
You must be signed in to change notification settings - Fork 14
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
Deserialization of JsonObject
from null
broken since 2.10.4
#18
Comments
Which version? Can you provide a unit test (or at least show code) to show the exact problem -- description can be helpful but I am not sure how to reproduce with just above. |
Here's a minimal reproducer: It only contains a test class that shows the problem. It worked until 2.10.3 and is broken since 2.10.4. |
Thank you @sithmein (from above link) package jsr353;
import javax.json.JsonObject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr353.JSR353Module;
public class Test {
public static class Pojo {
@JsonCreator
public Pojo(@JsonProperty("s") String s, @JsonProperty("o") JsonObject o) {
// does nothing
}
}
@org.junit.Test
public void testDeserialization() throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JSR353Module());
// this works
String s = "{\"s\": \"String\", \"o\": { \"a\": 1, \"b\": \"2\" } }";
mapper.readerFor(Pojo.class).readValue(s);
// this doesn't since 2.10.4
s = "{\"s\": \"String\"}";
mapper.readerFor(Pojo.class).readValue(s);
}
} |
Ah. This may be tricky thing to fix -- and very unfortunate breakage (wrt fix for #14) in patch release. Thank you for reporting this. I think I know what the issue is, and maybe how it could be addressed... but at least this test helps. |
JsonObject
from null
broken since 2.10.4
There's also another issue with this change: Code that relied on getting |
You can register a custom deserializer for that. |
Well, the change will break existing code no matter what and it will break during runtime and not compilation (which is worse). If Jackson followed semantic versioning (not sure if it does) then this would deserved a major version bump. In any case it should be mentioned prominently in the release notes. |
Jackson does follow semantic versioning, and change was to fix bug: I realize that this is gray area -- what I see as a bug you see as feature -- but I want to stress reasoning from my side: it was not (meant as) arbitrary change to semantics. Having said that, If you do feel strongly there should be a switch to allow alternate behavior (expose as nulls), I am open for a PR, but due to semantic versioning that will need to go in 2.12.0 (API additions should not go in patches). |
I found an (easy) way to work around (check for both |
Commit c9e71ed broke the deserialization of
JsonObject
parameters. Before this change missing properties were passed anull
to constructors. NowJsonValue.NULL
is passed which causesIllegalArgumentExceptions
during reflective instantiation becauseJsonValue.NULL
is not aJsonObject
.The text was updated successfully, but these errors were encountered: