Skip to content

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 jvmType)
public abstract C fromString(String text, TypeReference typeRef)
public abstract C fromReader(Reader reader, Class jvmType)
public abstract C fromReader(Reader reader, TypeReference typeRef)
public abstract C fromStream(InputStream is, Class jvmType)
public abstract C fromStream(InputStream is, TypeReference typeRef)
public abstract C fromAst(AstNode astNode, Class jvmType) Transforms an AST representation back into a specific Java type.
public abstract C fromAst(AstNode astNode, TypeReference typeRef)
public abstract Serializer registerTypeDescriptor(TypeDescriptor<?> typeDescriptor)
public abstract Serializer setParser(AstParser parser)
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:

SerializerException


toWriter

public abstract void toWriter(Object jvmInstance, Writer writer)

Throws:

IOException


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 jvmType)

Parameters:

text - The source text to parse and deserialize.

jvmType - The target type.

Returns:

A populated instance of the requested class.

Throws:

SerializerException


fromString

@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromString(String text, TypeReference typeRef)

Throws:

SerializerException


fromReader

@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromReader(Reader reader, Class jvmType)

Throws:

SerializerException


fromReader

@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromReader(Reader reader, TypeReference typeRef)

Throws:

SerializerException


fromStream

@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromStream(InputStream is, Class jvmType)

Throws:

SerializerException


fromStream

@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromStream(InputStream is, TypeReference typeRef)

Throws:

SerializerException


fromAst

@io.github.qishr.cascara.common.annotation.Nullable
public abstract C fromAst(AstNode astNode, Class jvmType)

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 typeRef)


registerTypeDescriptor

@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer registerTypeDescriptor(TypeDescriptor<?> typeDescriptor)


setParser

@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer setParser(AstParser parser)


setProviderFactoryEnabled

@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer setProviderFactoryEnabled(boolean b)


setHeuristicMatchEnabled

@io.github.qishr.cascara.common.annotation.NonNull
public abstract Serializer setHeuristicMatchEnabled(boolean b)


getParser

public abstract AstParser getParser()