# Mapping to custom objects

{% hint style="info" %}
You can map your custom objects starting from MBSection automatically using **`MBurgerMapper`** class.
{% endhint %}

Using the commodity class **`MBFieldsMapping`** which fields of your custom class should be mapped with the fields of the MBSection you named on your Project dashboard. Your destination object should at least override getters and setters and if you wish to obtain simple values or MBurger object values for:

* Images -> First **`MBImage`** (only an object, not an array)
* Media & Documents -> First **`MBFile`** (only an object, not an array)
* Addresses -> Latitude, longitude or textual address

You will find all possible simple data inside the **`MBMappingArgs`** class.&#x20;

{% hint style="info" %}
Make sure your custom class is public and that provides getters and setters for all fields you wish to map.
{% endhint %}

For example, for a simple **`News`** class with title and MBurger image

```java
class News: Serializable {
    var title: String?
    var img: MBImage?
}
```

Can be mapped this way:

```kotlin
val fieldsMapping = MBFieldsMapping()

//”ttl” is my custom object element, “Title” is the name of the Element we want to map from the section
fieldsMapping.putMap(“ttl”, “Title”)

//”img” is my custom object element, “Images” is the name of the Element we want to map from the section, we add “imageArguments” which tells to take only the first image from the array.
val imageArguments = arrayOf(MBMappingArgs.mapping_first_image_media)
fieldsMapping.putMap(“img”, “Images”, imageArguments)

//If getSimpleValues was “true” we would not have a single MBImage but the basic value, so the URL of the image and News class “img” should be a String
val getSimpleValues = false;
val nws = MBurgerMapper.mapToCustomObject(nkSection, fieldsMapping, News(), getSimpleValues) as News
```

{% hint style="info" %}
If you need to map images, the SDK will return a MBImages object, which contains an array of MBImage.

If you want an array of URLs you will have to set getSimpleValues to true.
{% endhint %}

{% hint style="warning" %}
Due to the new nature of Android 9 this functionaity could give you light greylist logcat messages because it uses reflections.&#x20;

For now on, there should be no problem, but this functionality may change with new Android releases.
{% endhint %}


---

# 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://docs.mburger.cloud/android-docs/mapping-to-custom-objects.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.
