Skip to content

add "fallbackStringForNullValue" attribute#49

Merged
g0ddest merged 3 commits intog0ddest:masterfrom
mariok:feature/default_string_for_null_values
Feb 10, 2026
Merged

add "fallbackStringForNullValue" attribute#49
g0ddest merged 3 commits intog0ddest:masterfrom
mariok:feature/default_string_for_null_values

Conversation

@mariok
Copy link
Contributor

@mariok mariok commented Feb 5, 2026

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.

@g0ddest
Copy link
Owner

g0ddest commented Feb 7, 2026

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:
Can you add some tests? At minimum:

Formatting with null field using the fallback
Round-trip: parse → format → parse (should get the same string back)
Make sure it doesn't break existing code without this attribute

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.
Docs would be nice - just a quick example in the README showing when/why to use this.
Also curious how it works with padding and align - does the fallback get padded/aligned or is it used as-is?

@mariok
Copy link
Contributor Author

mariok commented Feb 8, 2026

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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 8, 2026

@g0ddest g0ddest self-requested a review February 9, 2026 17:57
@g0ddest
Copy link
Owner

g0ddest commented Feb 9, 2026

Now it is much better, thank you! Could you also check the ./gradlew checkstyleMain output? Looks there are some issues there with long lines.

@mariok
Copy link
Contributor Author

mariok commented Feb 9, 2026

Sure, the checkstyle issues are fixed now.

Copy link
Owner

@g0ddest g0ddest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Will update in maven central shortly

@g0ddest g0ddest merged commit b07d939 into g0ddest:master Feb 10, 2026
1 check passed
@g0ddest
Copy link
Owner

g0ddest commented Feb 10, 2026

@mariok , the patch is accessible now on maven central with 0.14 https://central.sonatype.com/artifact/name.velikodniy.vitaliy/fixedlength/0.14

@mariok
Copy link
Contributor Author

mariok commented Feb 10, 2026

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants