Skip to content

[Go] Redesign Go serialization API with generics #2992

@chaokunyang

Description

@chaokunyang

Feature Request

Add Generics Support Fory Go, this will bring many benefits:

  • avoid interface box cost
  • type-safe API
  • Fast path for generic types: we can create a serializer for every generic container such as slice/map/array, and in all those serializer, we can avoid lots of type dispatch cost

Is your feature request related to a problem? Please describe

The current Go serialization API uses interface{} parameters which causes:

  • Unnecessary heap allocations when passing values
  • Extra struct copies for large objects
  • Type safety issues at compile time
  • Inconsistent API design compared to other languages

Describe the solution you'd like

Redesign the API to use:

  • Generic functions Serialize[T] and Deserialize[T] for type safety
  • Pointer-based parameters to avoid copies and allocations
  • Separate SerializeAny and DeserializeAny for polymorphic use cases
  • Clean separation between typed and untyped APIs

Benefits

  • Better performance by eliminating unnecessary allocations
  • Compile-time type safety
  • More idiomatic Go API design
  • Clearer distinction between static and dynamic typing use cases

Describe alternatives you've considered

No response

Additional context

#2982

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions