使用Studio 6.1.0
运行时3.8.2ee
我编写了一个dataweave脚本,当我在Transform Message窗口中预览结果时,该脚本工作正常,但是当我实际运行我的应用程序时,我收到一个错误,表明dataweave脚本存在问题。
这是错误:
Invalid input "[\n \t\t({\n \t\t\teffectiveTerm:
template.effectiveTerms.effectiveFromTerm,\n \t\t\tattributeCode: "VARU"\n \t\t} as :object
{ class: "edu.mit.courseleaf.domain.backfill.OldAttribute" })\n \t\twhen
template.units.variableUnits == "Y",", expected flatten, typeOf, using, unzip, capitalize,
avg, min, lower, upper, max, singularize, not, dasherize, ordinalize, camelize, trim, sizeOf,
value, pluralize, sum or underscore (line 16, column 24)
(java.util.concurrent.ExecutionException). Message payload is of type: HashMap
带有dataweave脚本的流程,用于预览的输入,用于实际执行的json包含在下面。几条评论:
使用dataweave脚本进行流程:
<flow name="temp-json-to-map-to-pojo-example-for-so">
<json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
<set-payload value="#[payload]" mimeType="*/*" doc:name="Set Payload"/>
<dw:transform-message doc:name="Transform Message">
<dw:input-payload doc:sample="sample_data/map.dwl"/>
<dw:set-payload><![CDATA[%dw 1.0
%input payload application/java
%output application/java
%function passThroughAttributes(attributeList) attributeList - "RPT" - "SWE" - "FSEM"
---
using (template = payload.subjectTemplate
, attributes = payload.subjectTemplate.attributes
)
{
subjectCode:template.mainSubjectCode,
subjectNumber:template.mainSubjectNumber,
attributes: flatten [
({
effectiveTerm: template.effectiveTerms.effectiveFromTerm,
attributeCode: "VARU"
} as :object { class: "edu.mit.courseleaf.domain.backfill.OldAttribute" })
when template.units.variableUnits == "Y",
passThroughAttributes(attributes) map (
{
attributeCode: $,
effectiveTerm: template.effectiveTerms.effectiveFromTerm
}
) as :object { class: "edu.mit.courseleaf.domain.backfill.OldAttribute" }
]
}as :object{class : "edu.mit.courseleaf.domain.backfill.SourceSubject"
]]></dw:set-payload>
</dw:transform-message>
</flow>
预览示例输入:
{
subjectTemplate: {
subjectTemplateId: "43C9C99A88B76AFBE053282701126517",
mainSubjectCode: "HAA",
mainSubjectNumber: "T101",
subjectLevel: "U",
effectiveTerms: {
effectiveFromTerm:"2017SP",
effectiveThruTerm: "999999"
},
units: {
variableUnits: "Y",
lectureUnits: 9,
labUnits: 3,
prepUnits: 0,
totalCreditLimitUnits: 0
},
attributes: ["RPT", "XLIS"]
}
}
预览的屏幕截图,显示正确填充的属性属性 流的实际JSON输入
{
"subjectTemplate": {
"subjectTemplateId": "43C9C99A88B76AFBE053282701126517",
"mainSubjectCode": "HAA",
"mainSubjectNumber": "T101",
"subjectLevel": "U",
"effectiveTerms": {
"effectiveFromTerm": "2017SP",
"effectiveThruTerm": "999999"
},
"units": {
"variableUnits": "Y",
"lectureUnits": 9,
"labUnits": 3,
"prepUnits": 0,
"totalCreditLimitUnits": 0
},
"attributes": ["RPT", "XLIS"]
}
}