Structural type-safe access to JSON objects

You can use dynamic property access with parsed JSON data, which is powerful and convenient, but not type safe. For example, if you misspell a property name, the Gosu editor cannot catch the error at compile time.

Gosu provides APIs that allow you to generate type-safe code to access JSON data. These APIs protect your code against misspelling a property name. More errors can be caught at compile time. Additionally, this approach lets you create meaningful types that you can use in the rest of your code. For example, you can create a type that represents a person, a group, or complex hierarchical business data types.

Although JSON structural types are type safe and client code validates at compile time, JSON structural types do not perform the same validations as XML schemas such as XSDs. For example, Gosu JSON structural types do not check for non-nullable fields or enforce minimum or maximum numbers of list elements. You may need to write your own validation logic to enforce your application’s unique business logic and field validation.

Warning: If property names contain unusual characters or reserved Gosu keywords, the name is changed automatically and preserved in the @ActualName annotation. However, the built-in APIs that convert Gosu data to JSON do not use the data that the annotation preserves.

See also