Implicit Transformers

Useful transformers for subclasses mapping.

In this guide, we'll review two new built in transformers added in ShapeShift version 0.0.7, ImplicitMappingTransformer and ImplicitCollectionMappingTransformer.

ImplicitMappingTransformer

ImplicitMappingTransformer is used to transform subclasses mapped with ShapeShift. Lets look at the following example:

We have mapped Address class to its display class AddressDisplay.

@DefaultMappingTarget(AddressDisplay::class)
class Address {
    @MappedField
    var country: String? = null

    @MappedField
    var city: String? = null

    @MappedField
    var address: String? = null
}

class AddressDisplay {
    var country: String? = null
    var city: String? = null
    var address: String? = null
}

We can use ShapeShift to map Address to AddressDisplay. But what we do if Address is a subclass? We use the ImplicitMappingTransformer.

The ImplicitMappingTransformer uses the ShapeShift instance internally to map Address to AddressDisplay.

ImplicitCollectionMappingTransformer

ImplicitCollectionMappingTransformer has the same job as ImplicitMappingTransformer but for collections.

Last updated

Was this helpful?