Skip to content

Shortcutting Structures

Alexey Valikov edited this page Jan 27, 2015 · 1 revision

Shortcutting a value property

If your class has a value property, you can shortcut its value.

Assume your class has a double-typed value property data. This would correspond to the following structure:

{
    data: 1.234
}

Shortcutting the value property of the class would mean you could provide its value directly rather than in an object. Simply:

1.234

When marshalling the class with this value, Jsonix will find out that it does not have a suitable type (is not an object). But it will then check your class and find out that you have a value property there and use that property to marshal the value. This saves a few lines in your JS structure. As a result, you'll get something like <data>1.234</data> in both cases.

Please see the Fiddle for example.

Note, however, that this only applies to marshalling. Unmarshalling will still give you an object structure.

Shortcutting a single property

Similarly to the shortcutting a value property described above, you can also shortcut a single property. That is, if the value is not suitable (not an object), but your class has just a single property, Jsonix will use that property to marshall you value.

Note, once again, that this only applies to marshalling. Unmarshalling will still give you an object structure.