0

I'm in an activity of exchanging Jackson for Jsob-B and I am having a problem on use @JsonbTypeDeserializer and @JsonbTypeSerializer as told below.

I have an entity like this:

 public class User implements Serializable {

  private static final long serialVersionUID = 1L;

  private String login;

  @JsonbTypeDeserializer(Decrypting.class)
  @JsonbTypeSerializer(Encrypting.class)
  private String password;

  // getters and setter
}

And one test like this:

  @Test
  public void whenDeserializingUsingJsonbTypeDeserializer() throws IOException {

    String json = "{\"login\":\"admin\", \"password\":\"yfv_ntl3_Nbrv0139tDwRQ\"}";

    Jsonb jsonb = JsonbBuilder.create();

    User user = jsonb.fromJson(json, User.class);

    Assert.assertEquals(user.getPassword(), "test-string");
  }

When running the test, the Decryption class is trying to deserialize the login field, but, as you can see, only the password field has annotations.

Any way to fix it?

4

1 に答える 1