This is an automated email from the ASF dual-hosted git repository.
ramyav pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/olingo-odata4.git
The following commit(s) were added to refs/heads/master by this push:
new e8ca29c [OLINGO-1480]Error serializing BigDecimal when there is no
Edm Property(EdmAssistedSerializer)
e8ca29c is described below
commit e8ca29ca62be92faeb80d38c518a58170bb00a19
Author: ramya vasanth <[email protected]>
AuthorDate: Thu Sep 17 10:04:53 2020 +0530
[OLINGO-1480]Error serializing BigDecimal when there is no Edm
Property(EdmAssistedSerializer)
---
.../core/serializer/json/EdmAssistedJsonSerializer.java | 11 +++++++++--
.../core/serializer/json/EdmAssistedJsonSerializerTest.java | 13 +++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
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 @@ package org.apache.olingo.server.core.serializer.json;
import java.io.IOException;
import java.io.OutputStream;
+import java.math.BigDecimal;
import java.net.URI;
import java.util.List;
@@ -296,11 +297,17 @@ public class EdmAssistedJsonSerializer implements
EdmAssistedSerializer {
} 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 @@ package org.apache.olingo.server.core.serializer.json;
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 @@ public class EdmAssistedJsonSerializerTest {
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"));
+ }
}