When a key with an object for a value is not recognized, the remainder of the input is ignored.
There are a couple of reasons I believe the must-ignore policy does not apply here, and that this is a bug.
When JSON Binding implementation during deserialization encounters key in key/value pair that it does not recognize, it should treat the rest of the JSON document as if the element simply did not appear, and in particular, the implementation MUST NOT treat this as an error condition.
The specification says that the rest of the document should be treated as if the element did not appear. My interpretation is that only that key-value is to be ignored, otherwise the specification would say something like, "treat the rest of the JSON document as if it simply did not appear."
Remaining input is not ignored unless the unrecognized key has an object value. Strings, numbers, etc. do not trigger this problem. This suggests that the behavior is accidental rather than a deliberate interpretation applying the must-ignore policy to "the rest of the document."
This behavior violently violates the principle of least surprise.
Here is a test:
import java.util.Map;
import jakarta.json.bind.JsonbBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
class JsonbTest {
private static final String EXAMPLE = "{\"obj\":{\"foo\":\"bar\"},\"key\":\"val\"}";
public static class Fail {
public String key;
}
public static class Pass extends Fail {
public Map<String, String> obj;
}
@ParameterizedTest
@ValueSource(classes = { Pass.class, Fail.class })
void bindWithMissingProperties(Class<? extends Fail> clz) {
Fail fail = JsonbBuilder.create().fromJson(EXAMPLE, clz);
Assertions.assertEquals("val", fail.key);
}
}
When a key with an object for a value is not recognized, the remainder of the input is ignored.
There are a couple of reasons I believe the must-ignore policy does not apply here, and that this is a bug.
Here is a test: