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.

Method Summary

Modifier and Type Method Description
public abstract String toText(Object jvmInstance)
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 fromText(String text, Class jvmType)
public abstract C fromText(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(N astNode, Class jvmType) Transforms an AST representation back into a specific Java type.
public abstract C fromAst(N astNode, TypeReference typeRef)
public abstract Serializer registerTypeDescriptor(TypeDescriptor<?> typeDescriptor)
public abstract Serializer setParser(AstParser parser)

Method Details

toText

public abstract String toText(Object jvmInstance)

Parameters:

jvmInstance - The object to serialize.

Returns:

The formatted string (e.g., YAML or JSON).

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:

An AST representation of the provided object.


fromText

public abstract C fromText(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


fromText

public abstract C fromText(String text, TypeReference typeRef)

Throws:

SerializerException


fromReader

public abstract C fromReader(Reader reader, Class jvmType)

Throws:

SerializerException


fromReader

public abstract C fromReader(Reader reader, TypeReference typeRef)

Throws:

SerializerException


fromStream

public abstract C fromStream(InputStream is, Class jvmType)

Throws:

SerializerException


fromStream

public abstract C fromStream(InputStream is, TypeReference typeRef)

Throws:

SerializerException


fromAst

public abstract C fromAst(N 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

public abstract C fromAst(N astNode, TypeReference typeRef)


registerTypeDescriptor

public abstract Serializer registerTypeDescriptor(TypeDescriptor<?> typeDescriptor)


setParser

public abstract Serializer setParser(AstParser parser)