[OLINGO-1480]Client error when reading Decimal literal
This commit is contained in:
parent
a50c098644
commit
79bd10f430
|
@ -207,7 +207,13 @@ public class ClientPrimitiveValueImpl extends AbstractClientValue implements Cli
|
|||
} else {
|
||||
try {
|
||||
// TODO: set facets
|
||||
return type.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
Integer precision = Constants.DEFAULT_PRECISION;
|
||||
Integer scale = Constants.DEFAULT_SCALE;
|
||||
if (typeKind.equals(EdmPrimitiveTypeKind.Decimal) && value instanceof BigDecimal) {
|
||||
precision = ((BigDecimal) value).precision();
|
||||
scale = ((BigDecimal) value).scale();
|
||||
}
|
||||
return type.valueToString(value, null, null, precision, scale, null);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
|
|
|
@ -289,10 +289,15 @@ public class JsonDeserializer implements ODataDeserializer {
|
|||
: typeInfo == null ? node.asText()
|
||||
: typeInfo.getPrimitiveTypeKind().isGeospatial()
|
||||
? getGeoDeserializer().deserialize(node, typeInfo)
|
||||
: ((EdmPrimitiveType) typeInfo.getType())
|
||||
.valueOfString(node.asText(), true, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true,
|
||||
((EdmPrimitiveType) typeInfo.getType()).getDefaultType());
|
||||
: node.isBigDecimal()
|
||||
?((EdmPrimitiveType) typeInfo.getType())
|
||||
.valueOfString(node.asText(), true, null,
|
||||
node.decimalValue().precision(), node.decimalValue().scale(), true,
|
||||
((EdmPrimitiveType) typeInfo.getType()).getDefaultType())
|
||||
:((EdmPrimitiveType) typeInfo.getType())
|
||||
.valueOfString(node.asText(), true, null,
|
||||
Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, true,
|
||||
((EdmPrimitiveType) typeInfo.getType()).getDefaultType());
|
||||
}
|
||||
|
||||
private Object fromComplex(final ObjectNode node, final ObjectCodec codec)
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.olingo.client.core.serialization;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -296,8 +297,15 @@ public class JsonSerializer implements ODataSerializer {
|
|||
}
|
||||
} else {
|
||||
// TODO: add facets
|
||||
Integer precesion = Constants.DEFAULT_PRECISION;
|
||||
Integer scale = Constants.DEFAULT_SCALE;
|
||||
if(kind == EdmPrimitiveTypeKind.Decimal && value instanceof BigDecimal){
|
||||
BigDecimal bigDecimal = (BigDecimal)value;
|
||||
precesion = bigDecimal.precision();
|
||||
scale = bigDecimal.scale();
|
||||
}
|
||||
final String serialized = EdmPrimitiveTypeFactory.getInstance(kind)
|
||||
.valueToString(value, null, null, Constants.DEFAULT_PRECISION, Constants.DEFAULT_SCALE, null);
|
||||
.valueToString(value, null, null, precesion, scale, null);
|
||||
|
||||
if (isIEEE754Compatible && (kind == EdmPrimitiveTypeKind.Int64 || kind == EdmPrimitiveTypeKind.Decimal)
|
||||
|| !NUMBER_TYPES.contains(kind)) {
|
||||
|
|
|
@ -85,9 +85,10 @@ public final class EdmDecimal extends SingletonPrimitiveType {
|
|||
final int decimals = matcher.group(2) == null ? 0 : matcher.group(2).length();
|
||||
return (precision == null || (significantIntegerDigits >= 0 &&
|
||||
significantIntegerDigits <= precision - ((scale == null) ? 0 : scale))) &&
|
||||
(decimals >= 0 && decimals <= ((scale == null) ? 0 : scale));
|
||||
(( decimals == 0 && ((scale == null) ? 0 : scale) < 0) ||
|
||||
(decimals >= 0 && decimals <= ((scale == null) ? 0 : scale)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean validateDecimals(final String value,
|
||||
final Boolean isNullable, final Integer maxLength, final Integer precision,
|
||||
|
|
Loading…
Reference in New Issue