Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json serializers refactoring #1979

Merged
merged 7 commits into from
Oct 4, 2021
Merged

Json serializers refactoring #1979

merged 7 commits into from
Oct 4, 2021

Conversation

pm47
Copy link
Member

@pm47 pm47 commented Sep 30, 2021

Best reviewed commit-by-commit.

Having custom serializers depend on external format would introduce an
infinite recursion at runtime if not careful. Thankfully, none of our
serializers use it, so we may as well remove the possibility entirely.
We don't need to type the serializers: this is required for deserializing,
not serializing, and we are not using it.

The fact that be had a type mismatch here shows it:
```scala
object TransactionSerializer extends MinimalSerializer[TransactionWithInputInfo]
```
Instead of providing a `MyClass => JValue` conversion method, we
provide a `MyClass => MyClassJson` method, with the assumption that
`MyClassJson` is serializable using the base serializers.

The rationale is that it's easier to define the structure with types
rather than by building json objects.

This also means that the serialization of attributes of class C is out
of the scope when defining the serializer for class C. See for example
how `DirectedHtlcSerializer` doesn't need anymore to bring in
lower level serializers.

It also has the advantage of removing recursion from custom serializers
which sometimes generated weird stack overflows.
@pm47 pm47 marked this pull request as ready for review October 1, 2021 12:44
@pm47 pm47 requested a review from t-bast October 1, 2021 12:44
@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2021

Codecov Report

Merging #1979 (601fff1) into master (6dc836d) will increase coverage by 0.04%.
The diff coverage is 62.50%.

@@            Coverage Diff             @@
##           master    #1979      +/-   ##
==========================================
+ Coverage   87.63%   87.67%   +0.04%     
==========================================
  Files         158      158              
  Lines       12416    12410       -6     
  Branches      530      518      -12     
==========================================
  Hits        10881    10881              
+ Misses       1535     1529       -6     
Impacted Files Coverage Δ
...n/scala/fr/acinq/eclair/json/JsonSerializers.scala 87.09% <62.50%> (+0.61%) ⬆️
...cinq/eclair/payment/receive/MultiPartHandler.scala 95.20% <0.00%> (-1.60%) ⬇️
...clair/channel/publish/ReplaceableTxPublisher.scala 85.88% <0.00%> (-1.18%) ⬇️
...main/scala/fr/acinq/eclair/io/PeerConnection.scala 84.16% <0.00%> (-0.42%) ⬇️
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 88.27% <0.00%> (+0.07%) ⬆️
...cala/fr/acinq/eclair/payment/relay/NodeRelay.scala 97.56% <0.00%> (+1.62%) ⬆️
...main/scala/fr/acinq/eclair/router/Validation.scala 93.46% <0.00%> (+2.69%) ⬆️

Copy link
Member

@t-bast t-bast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, I like it! It's clearly easier to read and feels more natural.

t-bast
t-bast previously approved these changes Oct 1, 2021
@pm47 pm47 merged commit 3295881 into master Oct 4, 2021
@pm47 pm47 deleted the json-serializers-refacto branch October 4, 2021 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants