Skip to content

Consider disabling the derivation of nested data types during JsonCodeMaker.make as a configuration option #1226

Open
@mrooneytrimble

Description

There are some use cases where the default scheme of generating the JsonValueCodec can cause some issues when migrating from another library (such as play-json) where custom formats have been defined.

One good feature (IMO) about play-json is that all of the nested objects must have json encoder/decoder (Reads/Writes) in scope for the macro to succeed.

In my case we have a custom serialisation format written in play-json which I would like to move to jsoniter for speed. These encoder/decoder(s) are not defined on the companion objects for the classes in question because they come from an in house geometry library, which has no awareness of JSON at all. And unfortunately there are next to no unit tests for this json serialisation (although no doubt I will have to find some payloads in the wild and add some).

This would help in the migration for this use case, as it would force me to think about the serialisation of each data type

Proposal

Add a new configuration option to CodecMakerConfig something like val deriveNestedDataTypes: Boolean which will default to true.

Naively I think that it could be placed here, but no doubt it will be more complex than that

def inferImplicitValue(typeTree: Tree): Tree = c.inferImplicitValue(c.typecheck(typeTree, c.TYPEmode).tpe, silent = config.deriveNestedDataTypes)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions