Lagom 1.6.5 silently performs only partial deserialization when using custom deserializers
See original GitHub issueLagom Version (1.2.x / 1.3.x / etc)
1.6.5
API (Scala / Java / Neither / Both)
Java
Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)
MacOs Catalina 10.15.5
JDK (Oracle 1.8.0_112, OpenJDK 1.8.x, Azul Zing)
openjdk version “11.0.6” 2020-01-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.6+10, mixed mode)
Problem
- We have the RootEntityState class which we try to deserialize as illustrated below.
- Our class contains a
child
field, which class uses a custom deserializer. - In lagom 1.6.5 this custom deserializer will result in all fields below
child
(i.e. updatedAt and updatedBy fields) being silently deserialized to null values - In lagom 1.6.4 the deserialization worked just fine and updatedAt and updatedBy got set correct values.
- This issue is particularly dangerous since no error is thrown (unless we have for example lombok NonNull annotations, as in the example below, in which case an exception is thrown)
@Value
@Builder
@With
public class RootEntityState implements Jsonable {
// this is deserialzed successfully, since above `child`
@NonNull Long createdAt;
// We have the child object that uses a custom deserializer
Child child;
// after the the custom deserializer we have other fields below.
// These fields will resolve to NULL values in lagom 1.6.5.
// Because we have @Nonnull annotations an exception
// is thrown. Without the NonNull it would just silently set
// the rest of the fields to null
@NonNull Long updatedAt;
@NonNull String updatedBy;
}
@Value
@Builder
@With
@JsonDeserialize(using = ChildDeserializer.class)
public class Child {
@NonNull Long updatedAt;
@NonNull String updatedBy;
}
public class ChildDeserializer extends StdDeserializer<Child> {
public ChildDeserializer() {
this(null);
}
public ChildDeserializer(Class<?> vc) {
super(vc);
}
@Override
public Child deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode node = jp.readValueAsTree();
String updatedBy = node.get("updatedBy").asText();
Long updatedAt = node.get("updatedAt").asLong();
return Child.builder()
.updatedAt(updatedAt)
.updatedBy(updatedBy)
.build();
}
}
Reproducible Test Case
There is a fully reproducible test case here https://github.com/lapidus79/lagom-1-6-5-custom-deserializer-issue
- It will display everything working on 1.6.4 and failing on 1.6.5.
- I also tried to run on 1.6.4 but so that jackson was overridden to 2.11.4, and it still worked on 1.6.4. Which leads be to believe it is not directly related to jackson.
To reproduce run RootEntityStateTest
and test run will fail.
After that edit the project/plugins.sbt
and set lagom version to 1.6.4.
. Now reload and run test again and it will pass.
Also tried to debug 1.6.4 vs 1.6.5 and there is a a difference which might help:
https://github.com/lapidus79/lagom-1-6-5-custom-deserializer-issue/blob/master/lagom164_breakpoint_in_deser.png https://github.com/lapidus79/lagom-1-6-5-custom-deserializer-issue/blob/master/lagom165_breakpoint_in_deser.png
https://github.com/lapidus79/lagom-1-6-5-custom-deserializer-issue/blob/master/lagom_164_processing_continues_since_FIELD_NAME.png https://github.com/lapidus79/lagom-1-6-5-custom-deserializer-issue/blob/master/lagom165_where_processing_stops.png
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Credit goes to @jrudolph 😅
Brilliant @ignasi35! You are the GOAT 🙇♂️