MBurger Headless CMS
User GuideCMS HeadlessEngagement Platform
  • 🍔MBurger Documentation🍔
  • 🔑 API
    • Introduction
      • Getting Started
      • Structure
    • Common Path
      • Basics
      • POST Bodies
      • POST Relations
      • Evaluating Responses
    • API Authentication
    • Project
    • Blocks
      • Get Blocks
      • Get Block
    • Sections
      • Get Sections
      • Get Section
      • Create Section
      • Update Section
      • Delete Section
    • Media
      • Get All Media
      • Upload Media
      • Get Media
      • Delete Media
    • Integrations / Extensions
      • Authentication Provider
        • Registration
        • Login
        • Logout
        • Get Profile
        • Update Profile
        • Delete Profile
        • Change Password
        • Forgot Password
      • Live Messages
        • Get All Live Messages
        • Send Live Message
        • Delete Live Message
      • In-App Subscriptions
        • InApp Subscription
        • Resume InApp Subscription
      • Shopify
        • Create a Shopify private app
        • Enable Shopify in MBurger
        • Collections Editor
      • Stripe
        • Create Customer
        • Get Cards
        • Create Card
        • Make Default
        • Delete Card
        • Subscription
        • Cancel Subscription
        • Resume Subscription
        • Payment
    • Going Deeper
      • Available Data Types (Elements)
  • 📱 Android SDK
    • Introduction
    • Installation
    • Initialization
    • Fetch for blocks
    • Fetch sections from blocks
    • Mapping to custom objects
    • Admin
      • Delete a Section/Media
      • Create a new Section
      • Update an existing Section
    • Auth
      • Register a new user
      • Authenticate a user
      • User profile
      • Edit profile
      • Other features
    • Proguard Rules
    • Plugins
    • Sample Apps
      • MBurger Explorer
      • MBurger Radio
    • MBurger Apps
  • 🍏 iOS SDK
    • Introduction
    • Installation
    • Initialization
    • Fetch the project
    • Fetch blocks
    • Fetch sections
    • Media
    • Encoding & Decoding
    • Serialization & Equality
    • Admin
      • Add/Edit a section
      • Delete a section
      • Upload media
      • Delete a media
    • Auth
      • Register a user
      • Authenticate a user
      • Retrieve user information
      • Update user profile
    • Plugins
    • Sample Apps
      • MBurger Explorer
      • MBurger Radio
    • MBurger Apps
  • 💻 PHP SDK
    • Installation & Configuration
    • How to use
    • Support & Feedback
    • License
  • ☕ JavaScript SDK
    • Introduction
    • Installation
    • Configuration
    • Methods Reference
    • Support & Feedback
    • License
  • 🔷Flutter SDK
    • Installation
    • Initialization
    • Fetch the project
    • Fetch blocks
    • Fetch sections
    • Media
    • Admin
      • Add/Edit a section
      • Delete a section
      • Upload a media
      • Delete a media
    • Auth
      • Register a user
      • Authenticate a user
      • Retrieve user information
      • Update user profile
  • ❓How to?
    • Basic interactions
      • Blocks
        • Get a Single Block
        • Get multiple Blocks
      • Sections
        • Get a single Section
        • Get Multiple Sections
        • Create a Section
        • Update a Section
        • Delete a Section
    • Advanced section retrieval
      • Filter sections
      • Obtain distance from a section
      • Manage locales and the fallback language
      • Get a section by SLUG
      • Obtain only sections with a defined relation
    • Advanced section creation
      • Create a section with a relation
      • Set the value of a checkbox element
      • Create a section with a multiple or dropdown element
      • Create a section with a SLUG
      • Create a section with SEO
      • Send or schedule a push when creating a section
    • Set the visibility of a section
    • Get images with various format
  • 👻 Sample App
    • Introduction
    • Create an MBurger project
    • Create Home, News and Gallery blocks
    • Create the project
    • Setup the SDK
    • Query the API for items
    • Map your objects from MBurger objects
    • Implement push notifications
    • Take a bite
Powered by GitBook
On this page

Was this helpful?

  1. Android SDK

Mapping to custom objects

You can map your custom objects starting from MBSection automatically using MBurgerMapper class.

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.

Make sure your custom class is public and that provides getters and setters for all fields you wish to map.

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

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

Can be mapped this way:

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

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.

Due to the new nature of Android 9 this functionaity could give you light greylist logcat messages because it uses reflections.

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

PreviousFetch sections from blocksNextAdmin

Last updated 4 years ago

Was this helpful?

📱