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?

Luciano Borges
  • 817
  • 3
  • 12
  • 31

1 Answers1

0

After update for new versions, I had a problem with JsonbConfigProperties.FAIL_ON_UNKNOWN_PROPERTIES that I switched for YassonConfig.FAIL_ON_UNKNOWN_PROPERTIES and now everything works fine.

<dependency>
        <groupId>jakarta.json.bind</groupId>
        <artifactId>jakarta.json.bind-api</artifactId>
        <version>1.0.2</version>
</dependency>
<dependency>
        <groupId>org.eclipse</groupId>
        <artifactId>yasson</artifactId>
        <version>1.0.7</version>
</dependency>
Luciano Borges
  • 817
  • 3
  • 12
  • 31