Consuming/building Java's @Builder Pojos in Kotlin

I have a POJO builder written in Java class. I want to consume and build the POJO in my kotlin class. I’m getting compilation error that ‘builder’ is not defined
ex:

  1. (POJO builder java class)
    import lombok.Builder;
    import lombok.Data;
    import lombok.NonNull;

     @Builder
     @Data
     public class SampleResponse {
         private String claimCode;
         private String claimStatus;
     }
    
  2. Consuming and building the POJO with data in kotlin class:

// the below line is not working. .builder() is not recognized
SampleResponse.builder().claimCode("foo").claimStatus("bar").build()

1 Like

You cannot mix Java source with Lombok annotations and Kotlin in same module, because Lombok generates getters, setters etc at post compile phase. Builder is a part of byte code but it isn’t present in source code. You should split your Java with Lombok and Kotlin code into separate modules.

The issue with Lombok was already disuccess here.

2 Likes

Thanks for the answer, I managed to split Java with Lombok and Kotlin into seperate modules.

1 Like