Skip to content

During generic encoding/decoding existing instances of EncodeJson are ignored #13

@eskimor

Description

@eskimor

e.g. Nothing is not encoded as Null, the EncodeJson instance for Maybe is completely ignored when generically traversing a data structure containing a Maybe. This is because gEncodeJson' recursively invokes itself without using EncodeJson at all.

The result is, that generic encoding is very limited, because it is not possible to manually override parts of the process.

As gEncodeJson' only operates on spines, I don't really see how this can be fixed, unfortunately. Except for calling fromSpine on each recursion and checking whether there is an instance somehow and using it, if available. While this could theoretically work with some JS hackery, I believe fixing decoding is much harder, because you can not retrieve a value before having already decoded the JSON, but then it is already too late. (Except we could decode it twice if an instance is found.)

In any case - this is very hacky. Is this afterall because Haskell's generics are more powerful, that aeson does not have this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions