question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lagom 1.6.5 silently performs only partial deserialization when using custom deserializers

See original GitHub issue

Lagom 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:open
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ignasi35commented, May 3, 2021

Credit goes to @jrudolph 😅

2reactions
lapidus79commented, May 3, 2021

Brilliant @ignasi35! You are the GOAT 🙇‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to do a partial deserialization with Jackson - Stack Overflow
It works for both serialization and deserialization. If you, however, wants to store the raw JSON, then you could define a custom deserializer:...
Read more >
Lagom Lagom Issues - IssueHint
Lagom 1.6.5 silently performs only partial deserialization when using custom deserializers, open, 8, 2021-04-25, 2022-12-12.
Read more >
nexrender server | Want to install older version. - Inlife/Nexrender
Try understaning why we use the derivitive of the error function ... Lagom 1.6.5 silently performs only partial deserialization when using custom ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found