Skip to content

Commit

Permalink
feat: fix org.bson.types.Decimal128 to Double, for issue alibaba#2558
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean23 committed May 11, 2024
1 parent 45cc6b3 commit 1f3112e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/util/TypeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,23 @@ public static <T> T cast(Object obj, Class<T> targetClass, ObjectReaderProvider
break;
}
}
// fix org.bson.types.Decimal128 to Double
String objClassName = obj.getClass().getName();
if (objClassName.equals("org.bson.types.Decimal128") && targetClass == Double.class) {
ObjectWriter objectWriter = JSONFactory
.getDefaultObjectWriterProvider()
.getObjectWriter(obj.getClass());
if (objectWriter instanceof ObjectWriterPrimitiveImpl) {
Function function = ((ObjectWriterPrimitiveImpl<?>) objectWriter).getFunction();
if (function != null) {
Object apply = function.apply(obj);
Function DecimalTypeConvert = provider.getTypeConvert(apply.getClass(), targetClass);
if (DecimalTypeConvert != null) {
return (T) DecimalTypeConvert.apply(obj);
}
}
}
}

ObjectWriter objectWriter = JSONFactory
.getDefaultObjectWriterProvider()
Expand Down

0 comments on commit 1f3112e

Please sign in to comment.