Skip to content

Custom scalar does not allow generics #6156

Closed
@cvb941

Description

@cvb941

Version

4.0.0

Summary

I'm trying to setup an adapter for a Mass measurement from a float.

mapScalar("Mass", "io.nacular.measured.units.Measure<Mass>", "data.apollo.MassAdapter")

Notice that the target class has a type parameter.

Gradle sync fails with the following error:
Can't escape identifier `Measure<Mass>` because it contains illegal characters: <>

This is the adapter (for completeness):

val MassAdapter = object : Adapter<Measure<Mass>> {
    override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Measure<Mass> {
        val weightDouble = reader.nextDouble()
        return weightDouble.asMass(Mass.baseUnit)
    }

    override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Measure<Mass>) {
        writer.value(value.`in`(Mass.baseUnit))
    }
}

Steps to reproduce the behavior

No response

Logs

(Your logs here)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions