Apache Camel Bindy Unmarshall vs Marshall不同
我正在使用以怪异格式的固定长度数据。本质上是它的10个字符,但第一个字符表示标志。我能够使用下面的配置将数据列为整数,但是当返回时,我需要以原始格式获取数据。
我认为问题是该模式似乎仅在拆卸时使用,因为我将其更改为完全无效的东西,并且不会改变编组的结果。
我还尝试了以下内容,其中添加了领先的零,但是我还需要添加的标志字符。
@field:DataField(pos = 1, length = 10, pattern = "+0", align = 'R', paddingChar='0')
数据
+000000746
@FixedLengthRecord
@Link
data class Row(
@field:DataField(pos = 1, length = 10, pattern = "+0")
val messageBodyLength: Int? = null
)
// All of the routes are direct:
// First unmarshal the data
from(UNMARSHALL_ENDPOINT_URI)
.unmarshal()
.bindy(BindyType.Fixed, Row::class.java)
.to(UNMARSHALL_RESULT_MOCK_ENDPOINT_URI)
sendBody(UNMARSHALL_ENDPOINT_URI, "+000000746")
// returns a Row with messageBodyLength set to 746 as expected.
from(MARSHALL_ENDPOINT_URI)
.marshal()
.bindy(BindyType.Fixed, Row::class.java)
.convertBodyTo(String::class.java)
.to(MARSHALL_RESULT_MOCK_ENDPOINT_URI)
sendBody(MARSHALL_ENDPOINT_URI, Row(messageBodyLength=746))
// Returns " 746"
// Expected "+000000746"
谢谢!
I'm working with a piece of fixed length data that is in a weird format. Essentially its 10 characters, but the first one indicates the sign. I was able to unmarshal the data as an integer using the below configuration, but when marshaling back I need to get the data in the original format.
I think the issue is the pattern appears to only be used when unmarshalling, as I changed it to something completely invalid and it doesn't change the marshalled results.
I also tried the following, which add the leading zeros, but I also need the sign character added back.
@field:DataField(pos = 1, length = 10, pattern = "+0", align = 'R', paddingChar='0')
Data
+000000746
@FixedLengthRecord
@Link
data class Row(
@field:DataField(pos = 1, length = 10, pattern = "+0")
val messageBodyLength: Int? = null
)
// All of the routes are direct:
// First unmarshal the data
from(UNMARSHALL_ENDPOINT_URI)
.unmarshal()
.bindy(BindyType.Fixed, Row::class.java)
.to(UNMARSHALL_RESULT_MOCK_ENDPOINT_URI)
sendBody(UNMARSHALL_ENDPOINT_URI, "+000000746")
// returns a Row with messageBodyLength set to 746 as expected.
from(MARSHALL_ENDPOINT_URI)
.marshal()
.bindy(BindyType.Fixed, Row::class.java)
.convertBodyTo(String::class.java)
.to(MARSHALL_RESULT_MOCK_ENDPOINT_URI)
sendBody(MARSHALL_ENDPOINT_URI, Row(messageBodyLength=746))
// Returns " 746"
// Expected "+000000746"
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发现问题了。数字的模式字段需要指定区域设置。
骆驼:
数据格式:
绑定固定:
区域设置:默认
Found the issue. The pattern fields for numbers need to have a locale specified.
camel:
dataformat:
bindy-fixed:
locale: default