[OLINGO-1556]Fix scale handling of BigDecimals in EdmAssistedJsonSerializer

This commit is contained in:
ramya vasanth 2022-01-25 15:05:52 +05:30
parent 7c2b5f748b
commit 72d5e9195c
2 changed files with 23 additions and 1 deletions

View File

@ -310,7 +310,7 @@ public class EdmAssistedJsonSerializer implements EdmAssistedSerializer {
try {
Integer scale = null;
if (value instanceof BigDecimal) {
scale = ((BigDecimal) value).scale();
scale = Math.max(0, ((BigDecimal) value).scale());
} else {
scale = Constants.DEFAULT_SCALE;
}

View File

@ -678,4 +678,26 @@ public class EdmAssistedJsonSerializerTest {
serialize(serializerMin, metadata, null, entityCollection, null)
.contains("1.6666666666666667406815349750104360282421112060546875"));
}
@Test
public void entityCollectionWithBigDecimalPropertyIntegerInScientificNotation() throws Exception {
EntityCollection entityCollection = new EntityCollection();
BigDecimal b = new BigDecimal("1.52E+4");
entityCollection.getEntities().add(new Entity()
.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, b)));
Assert.assertTrue(
serialize(serializerMin, metadata, null, entityCollection, null)
.contains("15200"));
}
@Test
public void entityCollectionWithBigDecimalPropertyInScientificNotation() throws Exception {
EntityCollection entityCollection = new EntityCollection();
BigDecimal b = new BigDecimal("1.52123123E+4");
entityCollection.getEntities().add(new Entity()
.addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, b)));
Assert.assertTrue(
serialize(serializerMin, metadata, null, entityCollection, null)
.contains("15212.3123"));
}
}