【发布时间】:2016-09-12 01:46:03
【问题描述】:
我有一个 JSON 到对象转换器,它遵循 Mule 3.6 工作流程中的数据映射器,发现 JSON 到对象转换器删除了十进制字段中的尾随零,因此 11.00 变为 11.0。
如果 JSON 到 Object 转换器的最后一个小数位为零,我如何防止它删除最后一个小数位并强制保留 2 个小数位,以便返回 11.00,因为这是一个要求?
显示问题的示例流程:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<data-mapper:config name="CSV_To_JSON" transformationGraphPath="csv_to_json.grf" doc:name="CSV_To_JSON"/>
<flow name="deimal-point-flowFlow">
<file:inbound-endpoint path="${file.unprocessed.location}" moveToPattern="#[message.inboundProperties['originalFilename']]" moveToDirectory="${file.unprocessed.location}" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="test.csv" caseSensitive="true"/>
</file:inbound-endpoint>
<data-mapper:transform config-ref="CSV_To_JSON" doc:name="CSV To JSON"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<json:object-to-json-transformer returnClass="java.lang.String" mimeType="application/json" doc:name="Object to JSON"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
</mule>
test.csv 文件如下所示:
DeptID,Dept,Staff
5LL/A,Human Resources,4.00
【问题讨论】:
-
我发现我可以使用 jackson 对象映射器来保留小数点后 2 位,但它会将值更改为字符串。有没有办法使用杰克逊对象映射器但将字段值保留为小数?
标签: mule rounding transformer anypoint-studio