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:
hidden/fixed pattern handles output transformation (e.g., key becomes Key).
SubResources
Use SubResources when you need@FieldHint on nested properties:
@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 extendformae.SubResource and use the @SubResourceHint annotation:
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):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.
