我有一个简单的要求,即在Mule 4中将输入的JSON转换为平面文件,但我无法在线找到任何可靠的示例。我开始按如下方式创建示例架构,但无法正常工作。
test.ffd模式:
form: FLATFILE
id: 'test'
tag: '1'
name: Request Header Record
values:
- { name: 'aa', type: String, length: 10 }
- { name: 'bb', type: String, length: 8 }
- { name: 'cc', type: String, length: 4 }
dataweave:
%dw 2.0
output application/flatfile schemaPath='test.ffd'
---
{
aa : payload.a,
bb : payload.b,
cc : payload.c
}
输入JSON:
{
"a": "xxx",
"b": "yyy",
"c": "zzz"
}
但是没有说出来
Message : "java.lang.IllegalStateException - Need to specify structureIdent or schemaIdent in writer configuration, while writing FlatFile at
4| {
| ...
8| }
如何正确执行此操作?
假设您正在尝试输出固定宽度的文件,看起来像是,更改
form: FLATFILE
to
form: FIXEDWIDTH
请记住,仅当您具有单个结构时,才可以使用此FFD。您可以传递:
payload map {
aa: $.a,
...
}
如果有一个集合,它仍然可以使用,但是如果您需要多个结构,则将无法使用速记模式。
并且要解释为什么会出现此错误,请看一下这些文档,阅读“ Writer properties(for Flat File)”:
https://docs.mulesoft.com/mule-runtime/4.2/dataweave-formats#writer_properties_flat_file
错误消息告诉您遗漏了什么。
需要在编写器配置中指定structureIdent或schemaIdent
添加其中之一,它的flatfile或fixedwidth应该可以正常工作。
例如,添加segmentIdent:
%dw 2.0
output application/flatfile schemaPath = "test1.ffd",
segmentIdent = "test1"
---
payload map (a, index) -> {
aa: a.a,
bb: a.b,
cc: a.c
}
希望有帮助。
-在https://simpleflatservice.com创建Mulesoft应用程序>