Skip to content

feat: add to and from json functions#2473

Open
jonaslagoni wants to merge 4 commits intoasyncapi:nextfrom
jonaslagoni:improve_mar
Open

feat: add to and from json functions#2473
jonaslagoni wants to merge 4 commits intoasyncapi:nextfrom
jonaslagoni:improve_mar

Conversation

@jonaslagoni
Copy link
Copy Markdown
Member

Description

Related Issue

Checklist

  • The code follows the project's coding standards and is properly linted (npm run lint).
  • Tests have been added or updated to cover the changes.
  • Documentation has been updated to reflect the changes.
  • All tests pass successfully locally.(npm run test).

Additional Notes

Add new methods to TypeScript marshalling preset:
- toJson(): Record<string, unknown> - converts instance to plain object
- fromJson(obj): ClassName - creates instance from plain object
- marshal() now delegates to JSON.stringify(this.toJson())
- unmarshal() now delegates to fromJson()

This enables working with parsed JSON objects directly without
string serialization, useful for API responses or custom serialization.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 1, 2026

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit e10ab6d
🔍 Latest deploy log https://app.netlify.com/projects/modelina/deploys/69a4a2b809e4d40008944234

@jonaslagoni jonaslagoni changed the base branch from master to next March 1, 2026 20:06
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 1, 2026

@jonaslagoni
Copy link
Copy Markdown
Member Author

Date marshal produces date-time output for date-only format
High Severity

renderDateMarshal generates identical JSON.stringify(payload) for both date and date-time formats, but JSON.stringify(Date) always calls Date.toISOString() producing a full date-time string like "2023-01-01T00:00:00.000Z". For format: "date" types (like FormatDate), AJV validation expects YYYY-MM-DD strings per RFC 3339. This causes the explicitly documented validate({data: marshal(obj)}) workflow to fail for date format types, and downstream systems expecting date-only strings will receive date-time strings instead. isDateFormatModel treats both formats identically but the marshal needs to produce format-appropriate output.

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.

1 participant