Interface StateMixin


public interface StateMixin
Jackson mixin interface for configuring JSON serialization of State objects.

StateMixin provides Jackson annotations to enable flexible JSON serialization and deserialization of State objects using dynamic property handling. Unlike the other mixins which handle polymorphic types, this mixin focuses on enabling State objects to be serialized as flat JSON objects with arbitrary key-value pairs.

The mixin configures Jackson to:

  • Serialize the entire state map as top-level JSON properties using JsonAnyGetter
  • Deserialize any JSON properties directly into the state map using JsonAnySetter
  • Handle dynamic state properties without requiring predefined fields
  • Support arbitrary key-value pairs for flexible state management

Key features:

  • Flat serialization: State properties appear as top-level JSON fields
  • Dynamic properties: No need to predefine state structure
  • Type preservation: Object values maintain their types during serialization
  • Bidirectional mapping: Seamless serialization and deserialization

This approach enables State objects to function as flexible containers for agent context, configuration, and runtime data without requiring rigid schemas. It's particularly useful for:

  • Agent memory and context persistence
  • Dynamic configuration management
  • Inter-agent state sharing
  • Workflow state preservation

Example JSON representation:


 // State object with various properties
 {
   "currentUser": "john.doe",
   "sessionId": "sess-123",
   "preferences": {
     "theme": "dark",
     "language": "en"
   },
   "counters": {
     "interactions": 15,
     "errors": 0
   }
 }
 

The mixin eliminates the need for wrapper objects or nested structures, providing a clean, flat JSON representation that's easy to work with in both client and server environments.

Author:
Pascal Wilbrink