Skip to content

Overview

Concepts and Principles

Development

Overview

IDEs

API Explorer

Releases

Release Notes

TORO Integrate

Coder Studio

Coder Cloud

Bug Reports

Search

Using the Alias Property

Introduction

Gloop gives developers the ability to rename Gloop model properties during serialization1 using the Alias property. With this property, you can name a Gloop model property after a keyword2 or change it to something else so that it matches the requirements of your API.

The examples package demonstrates how the Alias property works via the PrintPerson.gloop service. Once this service is executed, it will transform the input to XML and JSON (renaming properties with aliases) and log the result to the console.

Related articles

Please see the following articles for more information:

Running the Service

Under the Coder Navigator, expand the examples package entry and navigate to the code folder. Afterwards, look for the aliasForSerializing package. This package contains two files, shown below:

1
2
3
4
5
6
examples
├── ...
└── code
    └── aliasForSerializing
        ├── Person.model
        └── PrintPerson.gloop

Running the PrintPerson.gloop service will provide an output similar to that shown below.

Output of PrintPerson.gloop

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
24/04/18 13:42:26.340 INFO  [Integrate]
<?xml version="1.0"?>
<input phone number="941-746-6620">
    <firstName>John</firstName>
    <last_name>Doe</last_name>
    <invalidNames _3mail="john.doe@example.com" %grade="97.0">
        <middle-name>Bambi</middle-name>
        <SSN#>220-90-5004</SSN#>
    </invalidNames>
</input>
24/04/18 13:42:26.384 INFO  [Integrate]
{
    "input": {
        "firstName": "John",
        "last_name": "Doe",
        "invalidNames": {
            "middle-name": "Bambi",
            "SSN#": "220-90-5004",
            "_3mail": "john.doe@example.com",
            "%grade": 97.0
        },
        "phone number": "941-746-6620"
    }
}

But what exactly are we looking at and what's so special about this service?

How It Works...

This example revolves around serializing a JSON or XML attribute/element to a name we want. A Gloop model, when provided with an invalid property name, will attempt to make it a valid name for it to be valid for Gloop and Groovy. During the serialization to JSON or XML, Gloop will use the Alias property. The Alias will also be used when reading or writing a property.

The Person.model Gloop model contains invalid property names, each assigned an alias for when it gets serialized. After the serialization, instead of the Gloop-assigned property names, the value of the Alias property will be used instead to write the output. When a property has an Alias, it will appear in brackets are the property itself in Gloop, as shown below:

Screenshot showing a Gloop Property with an Alias

Generate models from an existing source

You can generate Gloop models from an existing Gloop model, or a JSON or XML string, file, or schema.


  1. For example, creating the JSON representation of a Gloop model or creating a Gloop model out of a JSON string 

  2. Effects are only visible after serialization