Closed lusabo closed 4 years ago
hi @lusabo, thanks for raising this issue. Can you please include the code for the Encrypting
and Decrypting
classes referenced in the annotations?
Hi @aguibert , follow the codes:
public class Decrypting implements JsonbDeserializer<String> {
@Override
public String deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext, final Type type) {
String encryptedValue = jsonParser.getString();
try {
return EncryptDecryptUtil.decrypt(encryptedValue);
} catch (GeneralSecurityException e) {
throw new IllegalArgumentException("Could not decrypt value", e);
}
}
}
public class Encrypting implements JsonbSerializer<String> {
@Override
public void serialize(final String decryptedValue, final JsonGenerator jsonGenerator, final SerializationContext serializationContext) {
try {
jsonGenerator.write(EncryptDecryptUtil.encrypt(decryptedValue));
} catch (GeneralSecurityException e) {
throw new IllegalArgumentException("Could not encrypt value", e);
}
}
}
ok, everything appears to be written correctly. I suspect it is an implementation bug -- which JSON-B impl are you using? (probably Yasson or Johnzon)
Yasson. 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>
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:
And one test like this:
When running the test, the Decryption class is trying to deserialize the login field, but, as you can see, only the password field has the annotations.
Any way to fix it?