Class AgenticScopeSerializer
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidallowDeserializationPackagePrefix(String packagePrefix) Registers an additional type prefix (typically a package name) to be allowed during deserialization ofAgenticScopestate.static voidallowDeserializationType(Class<?> type) Registers a single class to be allowed during deserialization ofAgenticScopestate.static DefaultAgenticScopeDeserializes a JSON string into a AgenticScope object.static voidregisterForDeserializationPackageOf(Class<?> type) Convenience method that registers the package of the given class for deserialization and sets the class loader used to resolve types.static StringtoJson(DefaultAgenticScope agenticScope) Serializes a AgenticScope into a JSON string.static voidwithClassLoader(ClassLoader classloader) Sets theClassLoaderused to resolve types during deserialization ofAgenticScopestate.
-
Method Details
-
toJson
Serializes a AgenticScope into a JSON string.- Parameters:
agenticScope- AgenticScope to be serialized.- Returns:
- A JSON string with the contents of the AgenticScope.
- See Also:
-
fromJson
Deserializes a JSON string into a AgenticScope object.- Parameters:
json- JSON string to be deserialized.- Returns:
- A AgenticScope object constructed from the JSON.
- See Also:
-
allowDeserializationPackagePrefix
Registers an additional type prefix (typically a package name) to be allowed during deserialization ofAgenticScopestate.By default, the deserializer allows standard JDK types (
java.util.*,java.math.*, primitive wrappers). If your agents store domain objects in the agentic scope state, you must register their package prefix before deserialization occurs:AgenticScopeSerializer.allowDeserializationPackagePrefix("com.acme.");Registrations are process-wide and permanent: they apply to every subsequent deserialization in the JVM and cannot be removed. In tests this means a prefix registered by one test stays allowed for all later tests.
Registration is not retroactive: a type must be registered before the
fromJson(String)call that encounters it, otherwise that call fails withUnserializableAgenticScopeException. It takes effect immediately for all subsequent deserializations.- Parameters:
packagePrefix- the package prefix to allow (e.g."com.acme.")- Throws:
IllegalArgumentException- if the prefix is null or empty- See Also:
-
allowDeserializationType
Registers a single class to be allowed during deserialization ofAgenticScopestate.AgenticScopeSerializer.allowDeserializationType(Order.class);Registrations are process-wide and permanent: they apply to every subsequent deserialization in the JVM and cannot be removed. Register the type before the
fromJson(String)call that encounters it, otherwise that call fails withUnserializableAgenticScopeException.- Parameters:
type- the class to allow- See Also:
-
withClassLoader
Sets theClassLoaderused to resolve types during deserialization ofAgenticScopestate.By default, the deserializer uses the parent
ClassLoader. In environments where domain types are loaded by a different classloader , you must set the appropriateClassLoaderbefore callingfromJson(String), otherwise deserialization will fail with aClassNotFoundException.The setting is process-wide: it applies to every subsequent deserialization in the JVM.
- Parameters:
classloader- the class loader to use for resolving types- See Also:
-
registerForDeserializationPackageOf
Convenience method that registers the package of the given class for deserialization and sets the class loader used to resolve types.This is equivalent to calling:
AgenticScopeSerializer.allowDeserializationPackagePrefix(type.getPackageName() + "."); AgenticScopeSerializer.withClassLoader(type.getClassLoader());Use this when your agents store domain objects in the
AgenticScopestate and you want to allow all types in the same package with a single call:AgenticScopeSerializer.registerForDeserializationPackageOf(Order.class);Registrations are process-wide and permanent. Register the package before the
fromJson(String)call that encounters its types, otherwise that call fails withUnserializableAgenticScopeException.- Parameters:
type- a class whose package will be allowed and whose class loader will be used for type resolution- See Also:
-