Skip to content

fix(concerto-core): prevent TypeNotFoundException when serializing map with DateTime values - #1547

Open
sadSanta-07 wants to merge 1 commit into
accordproject:mainfrom
sadSanta-07:fix/map-datetime-serialization
Open

sadSanta-07 wants to merge 1 commit into
accordproject:mainfrom
sadSanta-07:fix/map-datetime-serialization

Conversation

@sadSanta-07

Copy link
Copy Markdown

Fixes #1546.

Root Cause:
In visitMapDeclaration, typeof value === 'object' captures dayjs instances (which represent DateTime at runtime) as well as null. This bypassed primitive handling and forced a lookup for "DateTime" in the ModelManager, throwing a TypeNotFoundException.

Solution:

  1. Guarded the object check with !Util.isNull(value).
  2. Added a check for ModelUtil.isPrimitiveType(...). If the map value is a primitive (like DateTime), it delegates directly to this.convertToJSON(), bypassing the custom class resolution.
  3. Added a comprehensive test case in jsongenerator.js mimicking the exact crash scenario to ensure it never regresses.

All tests are passing locally.

…p with DateTime values

Signed-off-by: pechkas <iffcogc34@gmail.com>

@mira-accord-project mira-accord-project Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tracking this down, and for adding a regression test. The bug is real: a Dayjs map value reaches modelManager.getType('DateTime') and throws, and routing primitive map values through convertToJSON is the right idea. To make this mergeable: rebase onto the current main and keep its relationship handling in visitMapDeclaration, cover map values that are a scalar extending DateTime, and trim the whitespace-only edits so the diff shows just the fix. CI is also failing and the branch has conflicts, so please re-run it after the rebase.

Nothing blocking; some suggestions below. Findings: 2 should-fix, 3 nit.

  • nit · hygiene: Pull request #1548 addresses the same issue (#1546) in the same function and also covers scalars, null values and utcOffset. Maintainers will want to merge only one, so it would help to say in the description how this PR differs, or to agree with the other author which one to take.

Automated review by Mira, an Accord Project agent, at 9e008f2. Findings are labelled blocking, should-fix or nit; a maintainer makes the final call.

: modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType());
const decl = modelFile.getModelManager().getType(valueType);
if (!Util.isNull(value) && typeof value === 'object') {
const mapValueDecl = mapDeclaration.getValue();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix · correctness

This branch is based on an older main. On main, visitMapDeclaration starts with if (mapDeclaration.getValue().isRelationship()) { value = this.processRelationship(...) } else if (typeof value === 'object') { ... }, and this diff has no such branch. If the merge conflict is resolved by taking this version, maps whose values are relationships would stop serializing correctly. Please rebase onto main, keep the relationship branch first, and put the primitive/DateTime handling alongside the existing object branch.

: modelFile.getFullyQualifiedTypeName(mapDeclaration.getValue().getType());
const decl = modelFile.getModelManager().getType(valueType);
if (!Util.isNull(value) && typeof value === 'object') {
const mapValueDecl = mapDeclaration.getValue();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix · correctness

Only a map whose value type is the primitive DateTime is fixed. For a map whose value is a scalar that extends DateTime, mapValueDecl.getType() returns the scalar's name, ModelUtil.isPrimitiveType is false, and a Dayjs object still goes down the modelManager.getType(...) / decl.accept(this, ...) path. A ScalarDeclaration does not appear to be handled by visit (it has no isTypeScalar/isField), so that case looks likely to still throw. I could not run it, so please confirm with a test. Resolve the scalar's underlying primitive type before choosing the branch (for example from the scalar declaration's getType()), and add a test for a scalar ... extends DateTime map value.

{
return obj;
}
case 'DateTime':

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · conventions

The diff includes formatting-only changes unrelated to the fix: spacing after if in visit, visitMapDeclaration and visitClassDeclaration, and the switch in convertToJSON re-indented so case sits inside switch. They add noise and make the real change harder to review, and they add to the conflicts. Please revert the formatting-only hunks and keep the diff to the change in visitMapDeclaration.


});

describe('#visitMapDeclaration', () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit · tests

The new test covers only Map<String, DateTime> with the default UTC offset. The null value guard and a non-zero utcOffset are changed in the code but not tested, and neither is the scalar case above. The test also calls require('../../src/serializer') inside the test body; moving it to the top of the file matches the rest of the suite. Please add small tests for a null map value, a non-zero offset, and a DateTime scalar value.

@mira-accord-project

Copy link
Copy Markdown

Thanks for the PR, @sadSanta-07. Serializing Map values that hold DateTime without a TypeNotFoundException fixes a real crash, and the test builds the map through the serializer, as a user would. Sorry it has waited 29 days for a reply.

One thing to know: open PR #1548 changes the same code in jsongenerator.ts for the same issue (#1546). The maintainers will probably want to pick one approach, so you may see a request to coordinate or to rebase after one of them lands. The Concerto maintainers have been asked to review. We aim to give a first review within a few working days, though I can't promise a date.

Drafted by an Accord Project agent, reviewed by a maintainer.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open with no activity. Remove the stale label or comment to keep it active. Only items with maintainer engagement are auto-closed.

@github-actions github-actions Bot added the Stale label Nov 21, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(concerto-core): JSONGenerator crashes with TypeNotFoundException when serializing Map with DateTime values

1 participant