Closed pjfanning closed 1 year ago
FYI. I bumped to this PR/change as the result of our team investigations on change in behavior of JSONObject.get("field") when the actual value is double/float.
Our team hit this behavior change with 2.15.2 version uptake and we couldn't find any workaround. Do you have any suggestion?
The code: new ObjectMapper().registerModule(new JsonOrgModule()).readValue("{\"value\": 0.5 }", JSONObject.class).get("value").getClass().getCanonicalName() returns java.lang.Double on 2.13.4 and java.lang.BigDecimal on 2.15.2.
I was hoping that we can, at least, control the behavior DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS but it has no effect.
Do you still plan to change the behavior to use getNumberValueExact() so that it returns Double correctly as before? Thank you for supporting the library!
@dlipin can you open a a new issue and provide a reproducible test case?
this test passes:
public void testDouble() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JsonOrgModule());
JSONObject val = mapper.readValue("{\"val\":0.5}", JSONObject.class);
assertEquals(0.5d, val.getDouble("val"));
}
JSONObject has methods that let you choose the format that you want the number in. If you want a double, you call getDouble(String)
.
@dlipin like @pjfanning suggested, we'd really need a separate issue with reproduction. I think I understand the problem but there is always possibility of misunderstanding.
Sorry for delay, I've filed a new issue: https://github.com/FasterXML/jackson-datatypes-misc/issues/39
Thank you @dlipin. As per my other note, I think we are going to go with the new behavior as it resolves an issue and there is a way to get Double
value to if necessary.