Skip to content

Commit f39b650

Browse files
committed
🐛 fix for server not properly formatting floats
1 parent cd74401 commit f39b650

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/main/java/com/mindee/parsing/generated/GeneratedObject.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@ public StringField asStringField() {
3232
* Represent the object as a standard {@link AmountField}.
3333
*/
3434
public AmountField asAmountField() {
35+
Double value;
36+
Object rawValue = this.get("value");
37+
if (rawValue instanceof Integer) {
38+
value = ((Integer) rawValue).doubleValue();
39+
}
40+
else if (rawValue instanceof Double) {
41+
value = (Double) rawValue;
42+
}
43+
else {
44+
throw new ClassCastException("Cannot cast " + rawValue + " to Double");
45+
}
3546
return new AmountField(
36-
(Double) this.get("value"),
47+
value,
3748
this.getConfidence(),
3849
this.getPolygon(),
3950
this.getPageId()

src/test/java/com/mindee/product/generated/GeneratedV1Test.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,15 @@ else if (featureValue.isList()) {
243243
}
244244
}
245245
}
246+
247+
@Test
248+
void whenAmountDeserialized_mustCastToDouble() {
249+
GeneratedObject intObject = new GeneratedObject();
250+
intObject.put("value", 5);
251+
Assertions.assertNotNull(intObject.asAmountField());
252+
253+
GeneratedObject doubleObject = new GeneratedObject();
254+
doubleObject.put("value", 5.0);
255+
Assertions.assertNotNull(doubleObject.asAmountField());
256+
}
246257
}

0 commit comments

Comments
 (0)