Skip to content

fix(javascript): preserve getTypeInfo in regenerated read serializer#3669

Merged
chaokunyang merged 2 commits into
apache:mainfrom
xhzq233:main
May 12, 2026
Merged

fix(javascript): preserve getTypeInfo in regenerated read serializer#3669
chaokunyang merged 2 commits into
apache:mainfrom
xhzq233:main

Conversation

@xhzq233
Copy link
Copy Markdown
Contributor

@xhzq233 xhzq233 commented May 11, 2026

Why?

TypeResolver.regenerateReadSerializer() returned a partial serializer object that missed getTypeInfo.

When runtime paths later call original.getTypeInfo() (for example in ReadContext type-meta regeneration flow), it can throw:

TypeError: original.getTypeInfo is not a function

What does this PR do?

  • Add getTypeInfo: serializer.getTypeInfo when registering the regenerated serializer in javascript/packages/core/lib/typeResolver.ts.
  • Keep regenerated serializer interface consistent with normal serializer instances.

Minimal reproduction:

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 serializer.getTypeInfo); // before: undefined, after: function
serializer.getTypeInfo();

Related issues

Fixes #3668

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

N/A (bug fix, no protocol/perf-path behavior change expected).

添加 getTypeInfo: serializer.getTypeInfo 到部分 serializer 对象,
防止反序列化时 getTypeInfo() 返回 undefined。
@xhzq233 xhzq233 requested a review from theweipeng as a code owner May 11, 2026 10:06
@chaokunyang
Copy link
Copy Markdown
Collaborator

@xhzq233 Thanks for fix this. Could you add a test to cover it?

…getTypeInfo

Add a typemeta regression test that asserts regenerateReadSerializer returns
an object exposing getTypeInfo for named structs.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@xhzq233
Copy link
Copy Markdown
Contributor Author

xhzq233 commented May 12, 2026

@chaokunyang Thanks for the review. I have added a regression test in javascript/test/typemeta.test.ts:

  • test name: regenerated read serializers keep getTypeInfo
  • assertion: regenerateReadSerializer(...) returns a serializer with getTypeInfo available for named structs

Local verification command:

npm --prefix javascript run test -- typemeta.test.ts

And I also verified fail/pass behavior:

  • on upstream main without this fix: this test fails (Expected function, Received undefined)
  • on this PR branch with fix: this test passes

@chaokunyang chaokunyang merged commit a603ff1 into apache:main May 12, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JavaScript] regenerateReadSerializer may return serializer without getTypeInfo

3 participants