tkblackbelt
tkblackbelt

Reputation: 391

Apache Camel Bindy Unmarshall vs Marshall is different

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!

Upvotes: 0

Views: 440

Answers (1)

tkblackbelt
tkblackbelt

Reputation: 391

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

camel: dataformat: bindy-fixed: locale: default

Upvotes: 0

Related Questions