8

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!

alexzimmer96
  • 996
  • 6
  • 14

1 Answers1

12

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.

Guillaume Smet
  • 9,921
  • 22
  • 29