diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java index c011fdd82..075903149 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializer.java @@ -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; } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java index ade9d5de5..84031a70a 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/EdmAssistedJsonSerializerTest.java @@ -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")); + } }