Lombok @Value annotation not generating @ConstructorProperties in Eclipse

756 Views Asked by At

I have the code below in a Maven project which compiles and runs from the command line (OpenJDK 15.0.2 running in Ubuntu under Windows Subsystem for Linux). It uses Lombok 1.18.20 and version 2.12.3 of the relevant Jackson libraries.

Eclipse 20210312-0638 is running under the Windows OpenJDK 15.0.2 (I had the same behaviour with the Eclipse built-in JRE, installed the windows JDK to see if it helped). Lombok 1.18.20 is installed in Eclipse (and shows up in the About... dialog).

When I run the class below as a Java application in Eclipse, I get:

Exception in thread "main" com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `lomboktest.Main$Input` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

I've decompiled the class files created by the command-line Maven build and by running the Maven update in Eclipse. The Eclipse version is missing the @ConstructorProperties annotation, but it's there in the command-line version. The constructor, getters and setters are being created by the @Value annotation as expected in the Eclipse version, so Lombok is doing the job to some extent.

I have lombok.config in the root directory of the project:

lombok.anyConstructor.addConstructorProperties = true
config.stopBubbling = true

If I add an explicit all-args contructor with the @ConfigurationProperties annotation, then everything runs fine in Eclipse.

I'm at a loss as to where to look to find the difference. I've tinkered with any annotation-related settings I can find in Eclipse, without success. I've seen some posts about module dependencies affecting the Lombok annotations, but I'm not (knowingly) using modules.

Can anybody suggest what I need to do to get this working in Eclipse, or at least something I can investigate next to work out what the problem is?

package lomboktest;

import java.io.InputStream;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import lombok.Value;

public class Main {

    @Value
    public static class Input
    {
        private String a;
        private String b;
    }

    public static void main(String[] args) throws Exception
    {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        try (InputStream input = Main.class.getResourceAsStream("/input.yml"))
        {
            System.out.println(mapper.readValue(input, Input.class));
        }
    }

}
1

There are 1 best solutions below

2
On

I eventually found the problem. Since annotations were working except for the one annotation which has to be turned on in lombok.config, I hypothesised that lombok.config wasn't loading, and pulled out and tested some of the code in Lombok that 'bubbles' up the directory structure to find the lombok.config file.

Conclusion: the bubbling doesn't work with folders with UNC paths. I'm not sure if it's a limitation of Java file IO or the way Lombok uses it. I have my source in Ubuntu under WSL so that my manual Maven build is a Linux one, which meant setting up the Eclipse projects under \wsl$\Ubuntu... That format of path doesn't survive the bubbling code.

The solution was to map a Windows drive to the \wsl$\ network location and delete & recreate all the Eclipse projects under the drive, so the project paths are now G:/... instead of \wsl$\Ubuntu...