Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] @JsonUnwrapped not copied to @Builder methods in Eclipse IDE for record #3315

Closed
MathiasDamMC opened this issue Dec 16, 2022 · 6 comments · Fixed by #3425
Closed

[BUG] @JsonUnwrapped not copied to @Builder methods in Eclipse IDE for record #3315

MathiasDamMC opened this issue Dec 16, 2022 · 6 comments · Fixed by #3425
Assignees
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug eclipse
Milestone

Comments

@MathiasDamMC
Copy link

MathiasDamMC commented Dec 16, 2022

Describe the bug
In Eclipes IDE lombok fails to copy the Jackson annotation @JsonUnwrapped from a record to the method on @builder's. This works fine outside of Eclipse IDE. This issue seems related to #2736

Notice, this seems to work fine if used with class rather than record

To Reproduce
Run the following test case, this will fail in Eclipse as the @JsonUnwrapped is not copied to the builder() class method inner(). The same test case will work outside of Eclipse.

package test;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.annotation.JsonUnwrapped;

import java.util.Arrays;

import lombok.Builder;
import lombok.extern.jackson.Jacksonized;

class RecordAnnotationsNotCopiedTest {
    @Builder
    @Jacksonized
    record Example(@JsonUnwrapped Inner inner) {}
    
    record Inner(String s) {}
    
    @Test
    void testLombok() throws NoSuchMethodException, SecurityException {
        var method = Arrays.asList(Example.builder().getClass().getMethods()).stream().filter(m -> m.getName().equals("inner")).findFirst().get();
        assertThat(method.getAnnotations().length).isEqualTo(1);

    }
}

Expected behavior
This should also work in Eclipse IDE.

Version info (please complete the following information):

  • Lombok v1.18.24
  • Platform Eclipse Version: 2022-06 (4.24.0)
@MathiasDamMC MathiasDamMC changed the title [BUG] [BUG] @JsonUnwrapped not copied to @Builder methods in Eclipse IDE for record Dec 19, 2022
@Rawi01
Copy link
Collaborator

Rawi01 commented May 7, 2023

This issue affects all copyable annotations on record components and is not limited to @Jacksonized or @JsonUnwrapped.

@Rawi01 Rawi01 added bug eclipse accepted The issue/enhancement is valid, sensible, and explained in sufficient detail labels May 7, 2023
@Rawi01 Rawi01 self-assigned this May 8, 2023
Rawi01 added a commit to Rawi01/lombok that referenced this issue May 10, 2023
@rzwitserloot rzwitserloot modified the milestones: next-version, v1.18.28 Aug 4, 2023
@namannigam
Copy link

namannigam commented Sep 26, 2023

@rzwitserloot @Rawi01 After this change, the intent was to also imply this over classes(not only records)?
Asking since, we figured this out the hard way, where the upgrade to Lombok 1.18.30 resulted in a few test setup failures in our application.

@lombok.Builder
@lombok.Getter
class CustomResponse implements Serializable {
    @jakarta.annotation.Nonnull
     private String [] messages;

     @jakarta.annotation.Nonnull
     private String status;
}

in our test case, we were able to mock this earlier as

CustomResponse.builder().messages(new String[]{"mock"}).build();

Of course, I acknowledge that the test case should have taken into consideration to mock CustomResponse with status.
But this piece of code doesn't work now. The signs are good but hoping that it implies across and we won't have to make changes back and forth.

@rzwitserloot
Copy link
Collaborator

rzwitserloot commented Sep 26, 2023

@namannigam I'm not quite sure what, specifically, is failing. How does @Json relate to your snippet in any way? I'm not all that familiar with serialization or mocking, so you're going to have to spell out exactly -stick this in a source file, compile it like this, using these libraries and tools (e.g. Jsonthisorthat).

Or, if it's solely about the fact that your CustomResponse.builder().messages(new String[]{"mock"}).build(); used to work but no longer does, explain exactly how that mock thing works. Why does it fail now? Include the exception, for example. Right now I need to spend 5 hours to try to reconstruct what you're doing before I can be sure I'm fixing the problem.

@namannigam
Copy link

The difference is in the auto generated .class file where the latest version 1.18.30 takes annotations like @Nonnull into considerations and throws NullpointerException while with previous version this wasn't the case. If you stil need a reproducible example, let me know and I would share that as soon as I get some time off work.

@Rawi01
Copy link
Collaborator

Rawi01 commented Sep 27, 2023

@namannigam I think you skipped 1.18.28 because we added support for jakarta.annotation.Nonnull in this release. That is unrelated to annotations on record components.

Changelog:

FEATURE: Jakarta has some non-null annotations (such as jakarta.annotation.Nonnull) which we now support. Issue #3346.

@namannigam
Copy link

@Rawi01 Got it, that should resolve my concern. My bad for not specifying that I was relying on the version upgrade of Lombok via spring-boot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted The issue/enhancement is valid, sensible, and explained in sufficient detail bug eclipse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants