Skip to content

Conversation

TomaszGaweda
Copy link
Contributor

@TomaszGaweda TomaszGaweda commented Sep 8, 2025

This PR fixes record serialization and deserialization when using Java Records with JacksonAnnotationExtension

Fixes #176

@TomaszGaweda TomaszGaweda marked this pull request as draft September 8, 2025 16:20
@TomaszGaweda TomaszGaweda marked this pull request as ready for review September 8, 2025 17:33
@TomaszGaweda TomaszGaweda changed the title Fix record serialization when using AnnotationBasedIntrospection Fix record serialization when using JacksonAnnotationExtension Sep 8, 2025
if (orig != null) {
newProp = APropBuilder.merge(orig, newProp);
}
((IndexedMap<String, APropBuilder>) _props)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rationale: we don't want to change position, because of the renaming

@TomaszGaweda
Copy link
Contributor Author

Hi @cowtowncoder, I'd very appreciate if you could take a look at this PR (of course nothing urgent). Thanks in advance!

@cowtowncoder
Copy link
Member

@TomaszGaweda sorry for delay, hoping to review this week (having to focus on 3.0.0-rc10 first). Just thought I'll add a note to let you know this is on my radar, todo list.

@TomaszGaweda
Copy link
Contributor Author

Thanks a lot @cowtowncoder for the update and no worries :)

cowtowncoder added a commit that referenced this pull request Sep 22, 2025
cowtowncoder added a commit that referenced this pull request Oct 12, 2025
Object value = prop.getReader().readNext(r, p);
values[prop.getIndex()] = value;
}
for (int i = 0; i < values.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

This would require a comment -- explaining that for primitive types nulls not allowed.

}
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
for (BeanPropertyReader prop : _propsByName.values()) {
Copy link
Member

Choose a reason for hiding this comment

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

This is rather inefficient with n*n complexity (although I guess mostly n if no nulls from missing entries?). Would be good to have either direct lookup (ordered array/List of props by index), or...

actually better idea, I think -- for records, pre-created Object[] with defaults for primitive values.
Then something like:

final Object[] values = Arrays.copyOf(preset, preset.length);

and avoid post-scanning?

Copy link
Member

@cowtowncoder cowtowncoder left a comment

Choose a reason for hiding this comment

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

Pretty good; we are almost there! Couple of small changes needed and we are good to go!

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.

Cannot Deserialize JSON with @JsonProperty Annotated Record Fields in Jackson-jr

2 participants