Package io.github.qishr.cascara.common.lang.processor
Interface Serializer
java.lang.Object
io.github.qishr.cascara.common.lang.processor.Serializer
All Implemented Interfaces:
Processor
All Known Implementing Classes:
AbstractSerializer
public interface Serializer
Handles the transformation between Java Objects (POJOs) and the AST or textual formats.This interface provides a high-level API for data binding, allowing users to move seamlessly between raw objects, structured ASTs, and the final string output.
Nested Class Summary
| Modifier and Type | Class | Description |
|---|---|---|
| public static | io.github.qishr.cascara.common.lang.processor.Serializer.Context |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
| public abstract String | toString(Object jvmInstance) | Converts a Java Object directly into its textual representation, for example JSON or YAML. |
| public abstract void | toWriter(Object jvmInstance, Writer writer) | |
| public abstract N | toAst(Object jvmInstance) | Transforms a Java Object into an AST representation. |
| public abstract C | fromString(String text, Class |
|
| public abstract C | fromString(String text, TypeReference |
|
| public abstract C | fromReader(Reader reader, Class |
|
| public abstract C | fromReader(Reader reader, TypeReference |
|
| public abstract C | fromStream(InputStream is, Class |
|
| public abstract C | fromStream(InputStream is, TypeReference |
|
| public abstract C | fromAst(AstNode astNode, Class |
Transforms an AST representation back into a specific Java type. |
| public abstract C | fromAst(AstNode astNode, TypeReference |
|
| public abstract Serializer |
registerTypeDescriptor(TypeDescriptor<?> typeDescriptor) | |
| public abstract Serializer |
setParser(AstParser |
|
| public abstract Serializer |
setProviderFactoryEnabled(boolean b) | |
| public abstract Serializer |
setHeuristicMatchEnabled(boolean b) | |
| public abstract AstParser |
getParser() |
Method Details
toString
@io.github.qishr.cascara.common.annotation.Nullable
public abstract String toString(Object jvmInstance)
Converts a Java Object directly into its textual representation, for example JSON or YAML.
Parameters:
jvmInstance - The object to serialize.
Returns:
Returns the formatted string (e.g., YAML or JSON). Returns null if the jvmInstance is null.
Throws:
toWriter
public abstract void toWriter(Object jvmInstance, Writer writer)
Throws:
toAst
public abstract N toAst(Object jvmInstance)
Transforms a Java Object into an AST representation.
Parameters:
jvmInstance - The POJO or collection to transform.
Returns:
Returns an AST representation of the provided object.
fromString
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromString(String text, Class
Parameters:
text - The source text to parse and deserialize.
jvmType - The target type.
Returns:
A populated instance of the requested class.
Throws:
fromString
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromString(String text, TypeReference
Throws:
fromReader
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromReader(Reader reader, Class
Throws:
fromReader
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromReader(Reader reader, TypeReference
Throws:
fromStream
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromStream(InputStream is, Class
Throws:
fromStream
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromStream(InputStream is, TypeReference
Throws:
fromAst
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromAst(AstNode astNode, Class
Transforms an AST representation back into a specific Java type.
Parameters:
astNode - The root AST node to interpret.
jvmType - The target type to instantiate and populate.
Returns:
A populated instance of the requested class.
fromAst
@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromAst(AstNode astNode, TypeReference
registerTypeDescriptor
@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer
setParser
@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer
setProviderFactoryEnabled
@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer
setHeuristicMatchEnabled
@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer
getParser
public abstract AstParser