1. Home
  2. GLU.Guide
  3. Integration Builder
  4. Unmarshalling and Marshalling
  5. Unmarshalling an Array or a Class to Store it as an Object

Unmarshalling an Array or a Class to Store it as an Object

If you have a payload with classes where you are only interested in the class as a whole with all its underlying attributes, i.e. you have no interest in what those underlying attributes are, you can utilise the ‘Store as Object’ option when unmarshalling your payload. When you select this option, the Attribute Name box will disappear, as you are not dealing with an attribute but with the full object. Instead, you can define a name for your object in the ‘Object / Collection’ path. Here’s an example:

If the object is nested within an array(s) or a class(es), you can set your Object / Collection Path to reference the full path to the object you are interested in. Here are examples:

  1. For an array:
ParentArrayName1[].SubArrayName1[].ObjectName
  1. For a class:

class1.class2.ObjectName

Classes, Objects and Arrays – the basics

Arrays and Objects are two data structures used in API Request and Response messages to organize data:

  • Array: Is a collection of similar data items stored in a single variable. Each item in the array has an index number that starts from 0, and you can access each item by its index number. For example, an array of numbers could be [1, 2, 3, 4, 5].
  • Object: Is a collection of key-value pairs where each key is a string and each value can be of any data type (numbers, strings, arrays, objects, etc.). You can access the values in an object by their keys. For example, an object could be: { “name”: “John”, “age”: 30, “city”: “New York” }

In the context of API Request and Response messages, Arrays and Objects can be used to structure data that is being sent or received, making it easier to access and manage.



An Object and a Class are related concepts in object-oriented programming (OOP), but they are not the same thing.


A Class is a blueprint or a template for creating objects. It defines the properties and methods that the objects created from that class will have. Classes are typically used to model real-world objects, and each object created from the class represents an instance of that class.


An Object, on the other hand, is an instance of a class. It has the properties and methods defined by the class, and can be used to store and manipulate data. An object is created from a class by calling the constructor of the class.


So, to summarize, a Class is a definition of a type of object, while an Object is an instance of that type of object.


Here’s an example in JSON API Response message that represents a list of books:

api_response = {
“books”: [
{
“title”: “The Great Gatsby”,
“author”: “F. Scott Fitzgerald”,
“year”: 1925
},
{
“title”: “To Kill a Mockingbird”,
“author”: “Harper Lee”,
“year”: 1960
}
]
}

In this example, Book is a Class that defines a type of object representing a book. It has three properties title, author, and year.

The API Response message is a JSON object that has an array of books, each represented by an object with properties title, author, and year. The code loops through the array of books in the API response and creates instances of the Book class for each book, storing them in the books list. The code then loops through the books list and prints the properties of each Book object.



“Books” in the api_response is an array of objects. Each object in the “books” array represents a book and has properties title, author, and year.

Was this article helpful?

Related Articles

Need Support?

Can't find the answer you're looking for?
Contact Support
Fill the form and we’ll contact you shortly

    I agree with

    cookies
    We uses cookies to make your experience on this website better. Learn more
    Accept cookies