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

0

更新新版本后,我遇到了JsonbConfigProperties.FAIL_ON_UNKNOWN_PROPERTIES的问题,我切换为YassonConfig.FAIL_ON_UNKNOWN_PROPERTIES现在一切正常。

<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>
于 2020-04-29T16:36:27.847 回答