Dataweave错误:将Excel转换为JSON时,您使用这些参数调用了函数“值选择器”

时间:2018-08-03 10:17:25

标签: mule anypoint-studio dataweave

我正在使用Anypoint 7和Mule 4.1。

我想从计算机上的文件夹中读取Excel(xlsx)文件并将其转换为JSON,但是我收到错误消息:

  

您使用以下参数调用了函数“值选择器”:

我认为这取决于流,但不确定如何解决。

感谢您的帮助

XML:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"
    xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
    xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp"
    xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
    <flow name="testFlow" doc:id="3030b14f-b215-4c85-a6a4-96236516c552" >
        <scheduler doc:name="Scheduler" doc:id="d0985a96-a23c-4e2c-80ae-d78a9acd938e" >
            <scheduling-strategy >
                <fixed-frequency timeUnit="SECONDS"/>
            </scheduling-strategy>
        </scheduler>
        <file:read doc:name="Read xlsx file" doc:id="90b40273-ec58-47de-a48b-9812c52a74ea" path="C:\apps\test-api\src\test\resources\input\myTestExcelFile.xlsx" config-ref="File_Config">
            <ee:repeatable-file-store-stream />
        </file:read>
        <ee:transform doc:name="Transform Message" doc:id="36dbec15-6e02-4fdf-8176-025ad7fdce61" >
            <ee:message >
                <ee:set-payload ><![CDATA[%dw 2.0
input payload application/xlsx
output application/json
---
payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
    custId: cUSTOMER."Customer Code" default "",
    custName: cUSTOMER.Name default ""
}
]]></ee:set-payload>
            </ee:message>
        </ee:transform>
        <logger level="INFO" doc:name="Log Message" doc:id="5142b6ff-9d04-4cb2-ba3b-7fec5e52dd9b" message='#[payload]' category="com.test"/>
    </flow>
</mule>

错误消息

ERROR 2018-08-03 11:03:34,628 [[MuleRuntime].cpuLight.02: [test-api].testFlow.CPU_LITE @75c313f3] [event: 0-7a8a0890-9704-11e8-900d-a44cc83a8228] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler: 
********************************************************************************
Message               : "You called the function 'Value Selector' with these arguments: 
  1: Binary
  2: Name ("CUSTOMER")

But it expects one of these combinations:
  (Array, Name)
  (Array, String)
  (Date, Name)
  (DateTime, Name)
  (LocalDateTime, Name)
  (LocalTime, Name)
  (Object, Name)
  (Object, String)
  (Period, Name)
  (Time, Name)

5| payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
   ^^^^^^^^^^^^^^^^
Trace:
  at map (line: 5, column: 1)
  at main (line: 5, column: 18)" evaluating expression: "%dw 2.0
input payload application/xlsx
output application/json
---
payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
    custId: cUSTOMER."Customer Code" default "",
    custName: cUSTOMER.Name default ""
}
".
Error type            : MULE:EXPRESSION
Element               : testFlow/processors/1 @ test-api:test.xml:21 (Transform Message)
Element XML           : <ee:transform doc:name="Transform Message" doc:id="36dbec15-6e02-4fdf-8176-025ad7fdce61">
<ee:message>
<ee:set-payload>%dw 2.0
input payload application/xlsx
output application/json
---
payload.CUSTOMER map ( cUSTOMER , indexOfCUSTOMER ) -> {
    custId: cUSTOMER."Customer Code" default "",
    custName: cUSTOMER.Name default ""
}</ee:set-payload>
</ee:message>
</ee:transform>

  (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

XLSX文件

enter image description here

1 个答案:

答案 0 :(得分:1)

我发现问题是我没有将File连接器上的MIME类型设置为application / xlsx

enter image description here

一旦我设置了它,它就会起作用。