[OLINGO-1480]Error serializing BigDecimal when there is no Edm Property(EdmAssistedSerializer)
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 b5ef2f9..dda5c12 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
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.OutputStream;
+import java.math.BigDecimal;
import java.net.URI;
import java.util.List;
@@ -296,11 +297,17 @@
} else {
String serialized = null;
try {
+ Integer scale = null;
+ if (value instanceof BigDecimal) {
+ scale = ((BigDecimal) value).scale();
+ } else {
+ scale = Constants.DEFAULT_SCALE;
+ }
serialized = type.valueToString(value,
edmProperty == null ? null : edmProperty.isNullable(),
edmProperty == null ? null : edmProperty.getMaxLength(),
- edmProperty == null ? Constants.DEFAULT_PRECISION : edmProperty.getPrecision(),
- edmProperty == null ? Constants.DEFAULT_SCALE : edmProperty.getScale(),
+ edmProperty == null ? null : edmProperty.getPrecision(),
+ edmProperty == null ? scale : edmProperty.getScale(),
edmProperty == null ? null : edmProperty.isUnicode());
} catch (final EdmPrimitiveTypeException e) {
final String name = edmProperty == null ? "" : edmProperty.getName();
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 5874847..ade9d5d 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
@@ -20,6 +20,8 @@
import java.io.IOException;
import java.math.BigDecimal;
+import java.math.MathContext;
+import java.math.RoundingMode;
import java.net.URI;
import java.util.Arrays;
import java.util.Calendar;
@@ -665,4 +667,15 @@
serialize(serializerMin, metadata, null, entityCollection, null));
}
+ @Test
+ public void entityCollectionWithBigDecimalProperty() throws Exception {
+ EntityCollection entityCollection = new EntityCollection();
+ BigDecimal b = new BigDecimal(1.666666666666666666666666666666667);
+ b.abs(new MathContext(0, RoundingMode.UNNECESSARY));
+ entityCollection.getEntities().add(new Entity()
+ .addProperty(new Property(null, "Property1", ValueType.PRIMITIVE, b)));
+ Assert.assertTrue(
+ serialize(serializerMin, metadata, null, entityCollection, null)
+ .contains("1.6666666666666667406815349750104360282421112060546875"));
+ }
}