Skip to content

Home

Development

IDEs

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

examples package: Using the Alias property

Gloop gives developers the ability to rename Gloop model properties during serialization1 and deserialization2 using the Alias property. With this property, you can:

  • name a Gloop model property after a Java/Groovy keyword (e.g. int, boolean, while);
  • have it contain special characters that are invalid in variable names in Java (e.g. !%toro*6, +hello); 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 aliasForSerializing.PrintPerson.gloop service. When this service is executed, it will transform the input to XML, JSON, and YAML; and then log the result to the console. The resulting XML, JSON, and YAML strings will show the properties that have been renamed with their aliases.

Related articles

Please see the following articles for more information:

Try it!

In the Navigator, expand the examples package and navigate to the code folder, then expand the aliasForSerializing package. This package contains two files, as shown below:

1
2
3
4
5
6
7
examples
├── ...
└── code
    └── aliasForSerializing
        ├── model
           └──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
INFO  [Martini]
<?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>
INFO  [Martini]
{
    "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 you looking at and what's so special about this service?

Explanation

This example shows how you can serialize a JSON, XML, or YAML attribute/element/property to any name you like. A Gloop model, when provided with an invalid property name, will attempt to make it a valid Gloop and Groovy name. The desired name will be configured as the property's Alias instead; and during serialization or deserialization to JSON, XML or YAML, Gloop will use the Alias property.

The Person.model Gloop model contains invalid property names, each assigned an alias that are used when it gets serialized. After 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 curved brackets after 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, a JSON, XML or YAML string or file, or a JSON or XML schema.


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

  2. For example, creating a Gloop model out of a JSON string.