# Instance Mapping

Due to the fact that ShapeShift uses reflection behind the scenes, destination **classes need a no arg constructor**. But in some cases you have no control over the destination classes and cannot modify them to add a no arg constructor. This is where Instance Mapping comes into play, you can pass already-instantiated destination objects to the `map` method.

{% hint style="info" %}
Version 0.0.7 of ShapeShift introduced new [Object Suppliers](https://shapeshift.krud.dev/features/object-suppliers) functionality as an improved solution for the no arg constructor issue.
{% endhint %}

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

```kotlin
@DefaultMappingTarget(SimpleEntityDisplay::class)
data class SimpleEntity(
    @MappedField
    val name: String,
    @MappedField
    val description: String,
    val privateData: String
)
```

{% endtab %}

{% tab title="Java" %}

```java
@DefaultMappingTarget(SimpleEntityDisplay.class)
public class SimpleEntity {
    @MappedField
    private String name;
    @MappedField
    private String description;
    private String privateData;
    // Getters and Setters...
}
```

{% endtab %}
{% endtabs %}

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

```kotlin
data class SimpleEntityDisplay(
    val name: String,
    val description: String
)
```

{% endtab %}

{% tab title="Java" %}

```java
public class SimpleEntityDisplay {
    private String name;
    private String description;

    public SimpleEntityDisplay(String name, String description) {
        this.name = name;
        this.description = description;
    }
    // Getters and Setters...
}
```

{% endtab %}
{% endtabs %}

`SimpleEntityDisplay` does not have a no arg constructor. You can either add a no arg constructor or initiate a new instance of `SimpleEntityDisplay` and pass it to the `map` function.

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

```kotlin
val shapeShift = ShapeShiftBuilder().build()
val simpleEntity = SimpleEntity("test", "test description", "private data")
val simpleEntityDisplay = SimpleEntityDisplay("", "")
// Passing simpleEntityDisplay as a destination instance 
val result = shapeShift.map(simpleEntity, simpleEntityDisplay)
```

{% endtab %}

{% tab title="Java" %}

```java
ShapeShift shapeShift = new ShapeShiftBuilder().build();
SimpleEntity simpleEntity = new SimpleEntity();
simpleEntity.setName("test");
simpleEntity.setDescription("test description");
simpleEntity.setPrivateData("private data");
SimpleEntityDisplay simpleEntityDisplay = new SimpleEntityDisplay("", "");
// Passing simpleEntityDisplay as a destination instance 
SimpleEntityDisplay result = shapeShift.map(simpleEntity, simpleEntityDisplay);
```

{% 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/instance-mapping.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.
