Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Lombok behaviour with Quarkus and Jackson

at the moment i'm facing a strange issue. I use lombok in my Quarkus project to have getter, setter etc. generated automatically. When i compile Quarkus to a native image, Jackson refuses to serialize a Lombok-Data-Object, but serializes a different one without problems.

Even stranger is, that this error only occurs when i compile a native binary and embed it into a container. Running both examples in the "quarkus:dev" profile works flawless.

Objects from this class get serialized:

@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "accounts")
public class AccountEntity {

    @Id
    @GeneratedValue(generator = "UUID")
    @GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
    @Column(name = "id", updatable = false, nullable = false)
    private UUID id;

    @Column(unique = true, name = "username", nullable = false)
    private String username;

    @Column(unique = true, name = "mail", nullable = false)
    private String mail;

    @Column(name = "password", nullable = false)
    private String password;

}

Objects from this class get not:

@Getter
@AllArgsConstructor
public class LoginResponse {
    private final String token;
}

The error message:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class de.alexzimmer.pwa.model.LoginResponse and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

But even if i take a look into the generated class-files, i can see public getters for both classes getting generated. I'm thankful for any advices and thoughts of how this could happen.

Thanks!

like image 726
alexzimmer96 Avatar asked Nov 18 '19 09:11

alexzimmer96


People also ask

Does Lombok work with Quarkus?

Lombok doest not work in quarkus extension.


1 Answers

You have to register this class for reflection by adding the @RegisterForReflection annotation.

It works for the first object as it's an entity and this is done automatically.

See https://quarkus.io/guides/writing-native-applications-tips#registering-for-reflection for a full explanation.

I will probably add the Jackson error message there so that it can be found more easily.

like image 178
Guillaume Smet Avatar answered Nov 09 '22 22:11

Guillaume Smet