Skip to content

[JavaScript] regenerateReadSerializer may return serializer without getTypeInfo #3668

@xhzq233

Description

@xhzq233

Search before asking

I searched existing issues and couldn't find a duplicate.

Version

  • Apache Fory commit: 33e0dc06 (upstream main as of 2026-05-11)
  • Component: JavaScript (@apache-fory/core)
  • Node.js: v22.18.0
  • OS: macOS (Darwin 24.6.0)

Minimal reproduce step

const core = require("./javascript/packages/core/dist/index.js");
const Fory = core.default;
const { Type } = core;

const fory = new Fory({ compatible: true });
const serializer = fory.typeResolver.regenerateReadSerializer(
  Type.struct({ namespace: "demo", typeName: "repro_struct" }, {
    id: Type.int32(),
  }),
);

console.log("typeof getTypeInfo =", typeof serializer.getTypeInfo);
serializer.getTypeInfo(); // throws

Observed output on upstream main:

typeof getTypeInfo = undefined
TypeError: serializer.getTypeInfo is not a function

What did you expect to see?

regenerateReadSerializer() should return a serializer that preserves the required serializer interface methods, including getTypeInfo.

What did you see instead?

In javascript/packages/core/lib/typeResolver.ts, regenerateReadSerializer() only forwards a subset of methods (getHash/read/...) to registerSerializer(...) and misses getTypeInfo.

This can crash runtime paths that call original.getTypeInfo(), for example in javascript/packages/core/lib/context.ts (getRegeneratedReadSerializerCache / genSerializerByTypeMetaRuntime).

Anything Else?

I have a local fix ready and can submit a PR:

return this.registerSerializer(typeInfo, {
  getHash: serializer.getHash,
  getTypeInfo: serializer.getTypeInfo,
  ...
});

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions