-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Is your feature request related to a problem? Please describe.
This test fails with a MismatchedInputException
:
@Test
public void testJsonValueIntToDouble() throws JsonMappingException, JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
Stuff a = mapper.readValue("5", Stuff.class);
assertEquals(5, a.value);
}
public static final class Stuff {
public final double value;
public Stuff(double value) {
this.value = value;
}
}
If the value being deserialized was 5.0
then it works. 5
does not work. I'm not interested in workarounds like adding extra constructors of type int
or long
, this should just work.
Normally there would be a @JsonValue
annotation on the field for serialization but that's not relevant for this issue so I've left it out.
I'm finding this hideous to solve in terms of overriding Jackson's default behaviour. Ideally Jackson would do it for me as default behaviour (or configured).
I'd like to override the default ValueInstantiator
used by an ObjectMapper
but that does not seem possible. Is it?
Can we change Jackson's default behaviour to support this use case? Or support a new DeserializationFeature
for this?
Describe the solution you'd like
see above
Usage example
see above
Additional context
No response