Mule 如何将复杂对象映射为DataWeave固定宽度格式
我有一个JSON对象Mule 如何将复杂对象映射为DataWeave固定宽度格式,mule,fixed-width,anypoint-studio,dataweave,Mule,Fixed Width,Anypoint Studio,Dataweave,我有一个JSON对象 { "collection": [ { "field1": "1111", "field2": "1122" }, { "field1": "2211", "field2": "2222" } ], "otherObject": { "otherField": "3333" } } 我希望得到以下输出: s01>1
{
"collection": [
{
"field1": "1111",
"field2": "1122"
},
{
"field1": "2211",
"field2": "2222"
}
],
"otherObject": {
"otherField": "3333"
}
}
我希望得到以下输出:
s01>1111~~~~~~~1122~~~~~~
s01>2211~~~~~~~2222~~~~~~
s02>3333~~~~~~
所以我使用了这个转换:
%dw 1.0
%output text/plain structureIdent = "response" , schemaPath = "response.ffd"
---
{
collection: payload.collection map ({
field1: $.field1,
field2: $.field2
}),
otherObject: {
otherField: payload.otherObject.otherField
}
}
我的回答是这样的
form: FIXEDWIDTH
structures:
- id: 'response'
name: response
tagStart: 0
data:
- { idRef: 'collection', count: '>1'}
- { idRef: 'otherObject', count: 1 }
segments:
- id: 'collection'
name: collection
tag: 's01>'
values:
- { name: 'field1', type: String, length: 10 }
- { name: 'field2', type: String, length: 10 }
- id: 'otherObject'
name: otherObject
tag: 's02>'
values:
- { name: 'otherField', type: String, length: 10 }
但我得到了这个结果
s02>3333~~~~~~
如果dataweave不知道我的数组,我应该如何使它工作?使用以下示例修改dataweave代码:
%dw 1.0
%output text/plain structureIdent = "response" , schemaPath = "response.ffd"
---
{
collection: flatten [payload.collection map ({
field1: $.field1,
field2: $.field2
})],
otherObject: {
otherField: payload.otherObject.otherField
}
}
[…map…]
展平
删除附加括号,因为映射
本身已返回数组collection: [{
field1: payload.collection.field1[0],
field2: payload.collection.field2[0]
},{
field1: payload.collection.field1[1],
field2: payload.collection.field2[1]
}]
使用以下示例修改DataWeave代码:
%dw 1.0
%output text/plain structureIdent = "response" , schemaPath = "response.ffd"
---
{
collection: flatten [payload.collection map ({
field1: $.field1,
field2: $.field2
})],
otherObject: {
otherField: payload.otherObject.otherField
}
}
[…map…]
展平
删除附加括号,因为映射
本身已返回数组collection: [{
field1: payload.collection.field1[0],
field2: payload.collection.field2[0]
},{
field1: payload.collection.field1[1],
field2: payload.collection.field2[1]
}]
非常感谢你,它像一个魅力!然而,这不是我们在dataweave文档中可以找到的解决方案:)非常感谢,它工作起来很有魅力!但是,这不是我们在dataweave文档中可以找到的解决方案:)