Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Expand Down Expand Up @@ -346,7 +346,7 @@
restore-keys: |
${{ runner.os }}-maven-
- name: Set up Gradle
uses: gradle/actions/setup-gradle@50e97c2cd7a37755bbfafc9c5b7cafaece252f6e
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5.0.2
with:
gradle-version: "8.13"
- name: Install Fory Java and Kotlin JSON artifacts
Expand Down
18 changes: 6 additions & 12 deletions javascript/packages/core/lib/typeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,8 @@ export class TypeInfo<T = unknown> extends ExtensibleFunction {
if (typeId !== undefined && typeName !== undefined) {
throw new Error(`type name ${typeName} and id ${typeId} should not be set at the same time`);
}
if (!typeId) {
if (!typeName) {
throw new Error(`type name and type id should be set at least one`);
}
if (typeId === undefined && !typeName) {
throw new Error(`type name and type id should be set at least one`);
}
if (typeId === undefined) {
const resolved = resolveNameParts(namespace, typeName!);
Expand Down Expand Up @@ -313,10 +311,8 @@ export class TypeInfo<T = unknown> extends ExtensibleFunction {
if (typeId !== undefined && typeName !== undefined) {
throw new Error(`type name ${typeName} and id ${typeId} should not be set at the same time`);
}
if (!typeId) {
if (!typeName) {
throw new Error(`type name and type id should be set at least one`);
}
if (typeId === undefined && !typeName) {
throw new Error(`type name and type id should be set at least one`);
}
if (typeId === undefined) {
const resolved = resolveNameParts(namespace, typeName!);
Expand Down Expand Up @@ -378,10 +374,8 @@ export class TypeInfo<T = unknown> extends ExtensibleFunction {
if (typeId !== undefined && typeName !== undefined) {
throw new Error(`type name ${typeName} and id ${typeId} should not be set at the same time`);
}
if (!typeId) {
if (!typeName) {
throw new Error(`type name and type id should be set at least one`);
}
if (typeId === undefined && !typeName) {
throw new Error(`type name and type id should be set at least one`);
}
if (typeId === undefined) {
const resolved = resolveNameParts(namespace, typeName!);
Expand Down
13 changes: 13 additions & 0 deletions javascript/test/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,17 @@ describe("object", () => {
expect(evolvingSerializer.deserialize(evolvingPayload)).toEqual({ f1: "payload" });
expect(fixedSerializer.deserialize(fixedPayload)).toEqual({ f1: "payload" });
});

test("should user type id 0 work", () => {
// TypeInfo allows user type ids in [0, 0xfffffffe]; a truthiness check on
// the numeric id treated 0 as "no id given" and threw.
const structInfo = Type.struct(0, { a: Type.int32() });
expect(structInfo.userTypeId).toBe(0);
expect(() => Type.enum(0, { A: 0 })).not.toThrow();
expect(() => Type.ext(0)).not.toThrow();

const fory = new Fory({ compatible: false });
const { serialize, deserialize } = fory.register(structInfo);
expect(deserialize(serialize({ a: 7 }))).toEqual({ a: 7 });
});
});
Loading