Apache Camel Bindy Unmarshall vs Marshall不同

发布于 2025-01-20 13:03:44 字数 1202 浏览 3 评论 0原文

我正在使用以怪异格式的固定长度数据。本质上是它的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2025-01-27 13:03:44

发现问题了。数字的模式字段需要指定区域设置。

骆驼:
数据格式:
绑定固定:
区域设置:默认

Found the issue. The pattern fields for numbers need to have a locale specified.

camel:
dataformat:
bindy-fixed:
locale: default

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文