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

Lombok 1.16.20 breaks Jackson serialization when using Builder annotation #12568

Closed
charlvictor opened this issue Mar 21, 2018 · 2 comments
Closed
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@charlvictor
Copy link

In Spring Boot 1.5.10 the lombok dependency was updated to 1.16.20, which has a breaking change on how constructor properties are generated when using the @Builder annotation. This basically breaks all your JSON serialization for the affected classes.

This is the issue logged against Lombok: projectlombok/lombok#1563

There are currently two workarounds that I tested that seems to work:

  1. Downgrade the Lombok dependency version to 1.16.18 why setting a property in your pom.xml
  2. Add a lombok.config file in your project root with the following property: lombok.anyConstructor.addConstructorProperties=true

To reproduce the problem, please see sample classes below:

@Data
@Builder
@AllArgsConstructor(onConstructor = @__(@JsonCreator))
public class CreateProductCommand {
    private String productName;
    private Integer initialStockLevel;
}

@RestController
@RequestMapping("/api/test")
public class TestController {

    @PostMapping
    public Product post(@RequestBody CreateProductCommand command) {

        Product product = new Product();
        product.setId(1L);
        product.setName(command.getProductName());
        product.setStockLevel(command.getInitialStockLevel());

        return product;
    }

}

When doing the POST to this endpoint, you will get a weird "Unsupported Media Type" exception, which was very confusing before finding the solution.

Error:

{
    "timestamp": 1521622061005,
    "status": 415,
    "error": "Unsupported Media Type",
    "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
    "message": "Content type 'application/json;charset=UTF-8' not supported",
    "path": "/api/test"
}

I am not sure what the long term fix for this would be. Maybe the lombok.config file should be included on the start.spring.io project template OR at least we should document the workaround somewhere in the Spring Boot documentation.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 21, 2018
@snicoll
Copy link
Member

snicoll commented Mar 21, 2018

Sorry but we can't document breaking changes in third party libraries. Spring Boot doesn't do anything with Lombok besides providing dependencies management for it so that's something that needs to be prominent in the Lombok release notes and/or documentation.

@snicoll snicoll closed this as completed Mar 21, 2018
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 21, 2018
@odrotbohm
Copy link
Member

This is related to this ticket in Jackson, because it's for some reason still requiring those additional annotations despite the fact that the Java 8 parameter names module is on the classpath. I.e. this is a Jackson issue fundamentally, not a Lombok one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

4 participants