Problematic property names for JSON structural types
The JSON object syntax supports a wider range of characters in the name part of the name-value pairs than Gosu supports for property names. For example, space characters are permissible in JSON object name fields but not Gosu property names. This makes it problematic to represent the structural type representation of this name as a Gosu property name. JSON also supports object name fields that would be Gosu reserved keywords such as new or class, and would cause syntax issues in type declaration or API usage.
For example, the following is legal JSON that requires special handling in Gosu structural types:
{
"Space Available": "8",
"new": "true",
"class": 1984
}
For problematic property names in generated structural types, Gosu generates alternative names that satisfy Gosu property name syntax as follows:
- For illegal characters, Gosu
substitutes the underscore character (
_). - For reserved keywords, Gosu reverses the case of the first character. Gosu keywords are case-sensitive, so this removes the conflict.
In both cases, Gosu preserves the original names in
the annotation @gw.lang.reflect.ActualName.
For the previous example JSON, the generated
structural type would include the following property getters and setters,
with the @ActualName annotation
as needed:
structure TestStructuralType {
...
@gw.lang.reflect.ActualName( "new" )
property get New(): String
@gw.lang.reflect.ActualName( "class" )
property get Class(): Integer
@gw.lang.reflect.ActualName( "Space Available" )
property get Space_Available(): String
}
@ActualName annotation. However,
the data preserved by the annotation is unused by the built-in APIs to
convert Gosu data to JSON.