# Implicit Transformers

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`.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
@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
}
```

{% endtab %}

{% tab title="Java" %}

```java
@DefaultMappingTarget(AddressDisplay::class)
public class Address {
    @MappedField
    private String country;

    @MappedField
    private String city;

    @MappedField
    private String address;

    // Getters and Setters...
}

public class AddressDisplay {
    private String country;
    private String city;
    private String address;

    // Getters and Setters...
}
```

{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
@DefaultMappingTarget(UserDisplay::class)
class User {
    @MappedField
    var name: String? = null

    @MappedField(transformer = ImplicitMappingTransformer::class)
    var address: Address? = null
}

class UserDisplay {
    var name: String? = null
    var address: AddressDisplay? = null
}
```

{% endtab %}

{% tab title="Java" %}

```java
@DefaultMappingTarget(UserDisplay::class)
public class User {
    @MappedField
    private String name;

    @MappedField(transformer = ImplicitMappingTransformer.class)
    private Address address;

    // Getters and Setters...
}

public class UserDisplay {
    private String name;
    private AddressDisplay address;

    // Getters and Setters...
}
```

{% endtab %}
{% endtabs %}

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

## ImplicitCollectionMappingTransformer

`ImplicitCollectionMappingTransformer` has the same job as `ImplicitMappingTransformer` but for collections.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
@DefaultMappingTarget(UserDisplay::class)
class User {
    @MappedField
    var name: String? = null

    @MappedField(transformer = ImplicitCollectionMappingTransformer::class)
    var addresses: List<Address>? = null
}

class UserDisplay {
    var name: String? = null
    var addresses: List<AddressDisplay>? = null
}
```

{% endtab %}

{% tab title="Java" %}

```java
@DefaultMappingTarget(UserDisplay::class)
public class User {
    @MappedField
    private String name;

    @MappedField(transformer = ImplicitCollectionMappingTransformer.class)
    private List<Address> addresses;

    // Getters and Setters...
}

public class UserDisplay {
    private String name;
    private List<AddressDisplay> addresses;

    // Getters and Setters...
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://shapeshift.krud.dev/guides/implicit-transformers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
