-
Notifications
You must be signed in to change notification settings - Fork 175
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
MismatchedInputException: No Object Id found for an instance of #378
Comments
I don't think this is Kotlin-specific, but I also do not thing this is a bug -- if you specify that a type is to have Object Id, it better have it. If not, that is an error condition. That is the intended behavior. There is an existing setting:
that you can disable which does change some of the requirements, but not sure it prevents this particular error (more meant to handle invalid Object Id references). I also wonder if you actually need Finally, it may be worth filing a separate RFE for |
For me it looks like a bug since it's an add-on to a data-binding functionality for Jackson, but it change an original behaviour. |
I did a little research and it looks like a bug (or inconsistency?) with First, the deserialization in @cowtowncoder |
@k163377 What would the possible fixes be? |
@cowtowncoder The first is to drop this validation. The second is to use the property name specified in the Third, even for setter-based deserialization, such input should be an error. I am not familiar with the |
@k163377 Ok I am not sure I understand the problem wrt property name (maybe you meant value instead?) I also still do not see why missing of an Object Id would be considered a false positive: input does not have the Object Id. Object Id cannot come from defaulting (it must be unique); Jackson's Object Id handling does require Object Id to come from input on deserialization -- this is not optional, or configurable (yet). But if there was to be an option to disable failure that'd be acceptable; someone would have to add it, implement. |
The following import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
public class ObjectId {
@JsonIdentityInfo(property = "id", generator = ObjectIdGenerators.PropertyGenerator.class)
static class MyStateObject {
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
@Test
void test() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
MyStateObject stateDataBind2 = mapper.readValue("{}", MyStateObject.class);
System.out.println(stateDataBind2.id); // -> null
}
}
If this is the case, I think it is necessary to perform validation when deserializing via |
That does sound like a bug @k163377 ... or I am misremembering rules. I agree that the handling via setter/field/constructors should NOT vary. Could you file a bug against |
@cowtowncoder |
This issue is closed because it is not |
Bug description
When I pass no value for an ID field with default value I get an exception:
"com.fasterxml.jackson.databind.exc.MismatchedInputException: No Object Id found for an instance of"
whereas com.fasterxml.jackson.databind.ObjectMapper sets default value.
To Reproduce
Expected behavior
Versions
Kotlin: 1.3.72
Jackson-module-kotlin: 2.9.9
Jackson-databind: 2.9.9
The text was updated successfully, but these errors were encountered: