簡體   English   中英

Dataweave轉換中涉及Mule 3.8.5中的JSON Payload的錯誤

[英]Error in Dataweave transformation involving a JSON Payload in Mule 3.8.5

在JSON有效負載上使用dataweave轉換時出現錯誤。 JSON有效負載為

{
    "requestId": "13431#1638a2abfb8",
    "result": [
        {
            "batchId": 1028,
            "importId": "1028",
            "status": "Queued"
        }
    ],
    "success": true
}

上面的有效負載是由RESTful服務返回的,在應用以下dataweave轉換之前,我已使用byteArray到Object轉換器將其轉換為對象

%dw 1.0
%output application/json
---
batchexecution:
 {
    batchid:payload.result[0].batchid,
    status: payload.result[0].status,
    success:payload.success 
 }  when ((payload.result != null) and (sizeOf payload.result  > 0)) 
 otherwise
 {
    batchid: 0,
    status:"Not queued",
    success:false
 }

我期望結果對象只有一條記錄,並且要檢查數組是否為null或它的大小是否大於0。 執行轉換代碼時出現以下錯誤。 不知道這里出了什么問題。

我期待轉換的以下輸出,但是在執行轉換代碼時出現錯誤

{
    "batchexecution": {
        "batchId": 1028,
        "status": "Queued",
        "success": true
    }
}

但由於您無法比較類型:: array的值,因此出現以下錯誤

Message               : Exception while executing: 
{"requestId":"64b3#1638e55058c","result":[{"batchId":1037,"importId":"1037","status":"Queued"}],"success":true}
                                         ^
You cannot compare a value of type ::array.
Payload               : {"requestId":"64b3#1638e55058c","result":[{"batchId":1037,"importId":"1037","status":"Queued"}],"success":true}
Payload Type          : java.lang.String
Element               : /marketing-dbmkt-etl-marketoFlow/processors/8 @ marketing-dbmkt-etl-marketo:marketing-dbmkt-etl-marketo.xml:69 (Transform Message)
Element XML           : <dw:transform-message doc:name="Transform Message" metadata:id="90448cfd-5884-441a-a989-e32e4877ac24">
                        <dw:input-payload mimeType="application/json" doc:sample="sample_data\batchreturnObject.dwl"></dw:input-payload>
                        <dw:set-payload>%dw 1.0%output application/json---batchexecution:{batchid:payload.result[0].batchid,status: payload.result[0].status,success:payload.success}  when ((payload.result != null) and (sizeOf payload.result  > 0))otherwise{batchid: 0,status:"Not queued",success:false}</dw:set-payload>
                        </dw:transform-message>
--------------------------------------------------------------------------------
Root Exception stack trace:
com.mulesoft.weave.mule.exception.WeaveExecutionException: Exception while executing: 
{"requestId":"64b3#1638e55058c","result":[{"batchId":1037,"importId":"1037","status":"Queued"}],"success":true}
                                         ^
You cannot compare a value of type ::array.
    at com.mulesoft.weave.mule.exception.WeaveExecutionException$.apply(WeaveExecutionException.scala:10)
    at com.mulesoft.weave.mule.WeaveMessageProcessor.execute(WeaveMessageProcessor.scala:121)
    at com.mulesoft.weave.mule.WeaveMessageProcessor.process(WeaveMessageProcessor.scala:67)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:108)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
    at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:88)
    at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
    at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
    at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
    at org.mule.processor.BlockingProcessorExecutor.executeNext(BlockingProcessorExecutor.java:98)
    at org.mule.processor.BlockingProcessorExecutor.execute(BlockingProcessorExecutor.java:59)
    at org.mule.interceptor.AbstractEnvelopeInterceptor.processBlocking(AbstractEnvelopeInterceptor.java:58)
    at org.mule.processor.AbstractRequestResponseMessageProcessor.process(AbstractRequestResponseMessageProcessor.java:47)
    at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:129)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:213)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:206)
    at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
    at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:35)
    at org.mule.execution.CommitTransactionInterceptor.execute(CommitTransactionInterceptor.java:22)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
    at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
    at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:67)
    at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
    at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
    at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
    at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
    at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
    at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:110)
    at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
    at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:205)
    at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:53)
    at org.mule.work.WorkerContext.run(WorkerContext.java:301)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

********************************************************************************

這里的問題並不明顯,但我之前也遇到過同樣的問題-它與sizeOf函數以及Mule對其某些運算符施加優先級的不良方式有關。 當您說(sizeOf payload.result > 0)它首先嘗試嘗試解析payload.result > 0表達式-因此,您將看到錯誤(它正在嘗試將數組與0進行比較)。

請改用((sizeOf payload.result) > 0) (出於這個原因,我總是在括號內加一個包裹sizeOf的點)。

附帶說明一下,您具有batchid:payload.result[0].batchid它應該是batchId:payload.result[0].batchId (在batchIdbatchId

每當您在dataweave中使用諸如sizeOf類的任何函數時,請嘗試使用大括號將其封裝,以避免此類錯誤。

@ghoshyTech您的情況

   when ((payload.result != null) and ((sizeOf payload.result)  > 0)) 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM