1

I have a POJO

@Data
@AllArgsConstrcutor
class Test {

T field1,
T field2,
}

When I am trying to deserialize it with jackson-databind 2.9.3,it is

failing com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.mypackage.Test (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (String)

dkb
  • 4,389
  • 4
  • 36
  • 54
Sakalya
  • 568
  • 5
  • 15

2 Answers2

3

@AllArgsConstructor creates a constructor with an argument for each field of the class (so, in your case, you'll get Test(T, T)).

For a default constructor, you should add the @NoArgsConstructor annotation:

@Data
@AllArgsConstrcutor // Won't be used by Jackson, but there's no harm in it, per-se
@NoArgsConstructor // Here!
class Test {
    T field1;
    T field2;
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
-1

Of course Lombok doesn't generate a default constructor.

With: @AllArgsConstrcutor you say you want it to generate a constructor with all the parameters provided. Since a POJO on it's own only needs one constructor, that 'll be it.

If you want a default constructor to be generated, add this: @NoArgsConstructor

Stultuske
  • 9,296
  • 1
  • 25
  • 37
  • This was working fine before I upgraded lombok to 1.16.22 – Sakalya Oct 25 '18 at 06:28
  • @Sakalya no, it didn't. Seeing as you misspelled "AllArgsConstructor", your code wouldn't even compile, let alone run and generate constructors it's not supposed to. That's also not the only issue in that Java file that prevents compilation. – Stultuske Oct 25 '18 at 06:33
  • Its just a typing mistake – Sakalya Oct 25 '18 at 06:38