Skip to main content
Some resource properties contain nested objects rather than simple values. There are two ways to model these in formae: plain classes and SubResources.

Plain Classes vs SubResources

The choice depends on whether you need field-level hints on the nested object’s properties.

Plain Classes

Use plain classes for simple nested structures where you don’t need @FieldHint annotations:
The hidden/fixed pattern handles output transformation (e.g., key becomes Key).

SubResources

Use SubResources when you need @FieldHint on nested properties:
The technical requirement: formae’s schema system only extracts @FieldHint annotations from properties if the containing class is a SubResource. FieldHints on plain class properties are ignored.

When to Use Each

Defining a SubResource

SubResources extend formae.SubResource and use the @SubResourceHint annotation:
Then reference it in your Resource:

Nested SubResources

SubResources can contain other SubResources for deeply nested structures:

Collections

For collections of nested objects, the approach depends on your needs: Plain class collection (no field hints):
SubResource collection (with field hints):
See Collection semantics for details on updateMethod and indexField.

Lifecycle

SubResources have no independent lifecycle:
  • Create: Serialized as nested data within the parent’s Properties
  • Read: The plugin returns the full nested structure
  • Update: Changes to SubResources trigger an update on the parent Resource
  • Delete: Deleting the parent removes all nested data

Summary

Start with plain classes for simple nested objects. Only use SubResource when you need @FieldHint annotations on nested properties. That’s when the extra ceremony pays off.