add "fallbackStringForNullValue" attribute#49
Conversation
|
Hey @mariok, thanks for the PR! The idea makes sense - being able to round-trip parse/format with null fields is definitely useful. A few things though: Formatting with null field using the fallback What happens if the fallback length doesn't match the field length? @FixedField(offset = 1, length = 10, fallbackStringForNullValue = "N/A") // ??Should probably validate or auto-pad it. |
|
Hi @g0ddest, thanks for your feedback. I have added the padding/align feature, so that the given fallback string will be automatically aligned and padded, if it is shorter than the field length. In case it is longer than the field length, an exception will be thrown with the necessary hints how to fix it. Also, some test cases and documentation has been added. |
|
|
Now it is much better, thank you! Could you also check the ./gradlew checkstyleMain output? Looks there are some issues there with long lines. |
|
Sure, the checkstyle issues are fixed now. |
g0ddest
left a comment
There was a problem hiding this comment.
Thank you! Will update in maven central shortly
|
@mariok , the patch is accessible now on maven central with 0.14 https://central.sonatype.com/artifact/name.velikodniy.vitaliy/fixedlength/0.14 |
|
Nice, thanks! |



This change allows to define fallback-values for fields, which will be used by the formatter, if the field value is null. This is important to keep the originally defined positions of the fields when formatting an object back into a fixed length string.
With this change an object, which has been created by parsing a fixed length string, can be formatted back into the exact same fixed length string again, even if some fields are empty or ignored in the original fixed length string.