Skip to content

feat(kotlin): Support for date and datetime from JSON schema#2845

Open
nikhilunni wants to merge 3 commits into
glideapps:masterfrom
nikhilunni:master
Open

feat(kotlin): Support for date and datetime from JSON schema#2845
nikhilunni wants to merge 3 commits into
glideapps:masterfrom
nikhilunni:master

Conversation

@nikhilunni

@nikhilunni nikhilunni commented Oct 31, 2025

Copy link
Copy Markdown

Description

Add support for JSON Schema format: date-time, format: date, and format: time in the Kotlin code generator. These formats now generate proper java.time.* types instead of String.

This implementation follows the same pattern as Java's date-time support, using:

  • OffsetDateTime for format: "date-time"
  • LocalDate for format: "date"
  • OffsetTime for format: "time"

The feature works across all Kotlin frameworks: just-types, jackson, klaxon, and kotlinx.

Related Issue

Fixes #2460

Motivation and Context

We prefer Kotlin generation to Java generation for nullability propagation, but did not support datetime formatting, as Java does. Plus, saw there was a longstanding issue for this.

Previous Behaviour / Output

For the given JSON schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "eventDate": {
      "type": "string",
      "format": "date"
    },
    "eventTime": {
      "type": "string",
      "format": "time"
    },
    "plannedDateTime": {
      "type": "string",
      "format": "date-time"
    }
  }
}

It would output:

package quicktype

data class MySchema (
    val eventDate: String,
    val eventTime: String,
    val plannedDateTime: String
)

New Behaviour / Output

package quicktype

import java.time.OffsetDateTime
import java.time.LocalDate
import java.time.OffsetTime

data class MySchema (
    val eventDate: LocalDate,
    val eventTime: OffsetTime,
    val plannedDateTime: OffsetDateTime
)

How Has This Been Tested?

Manual Testing

  • Tested with the existing test/inputs/schema/date-time.schema file
  • Verified output for all Kotlin frameworks:
    • --framework just-types
    • --framework jackson
    • --framework klaxon
    • --framework kotlinx
  • Tested with the exact schema from issue Kotlin date and datetime types are generated as strings from json schema #2460
  • Verified proper handling of:
    • Simple date-time properties
    • Date-time types in unions
    • Date-time types in arrays
    • Complex nested structures with date-time types

Automated Testing

  • Added "date-time" feature to KotlinLanguage test configuration
  • Added "date-time" feature to KotlinJacksonLanguage test
    configuration
  • Follows the same pattern as the Golang date-time feature
    implementation (commit 1f89a97)

@nikhilunni

Copy link
Copy Markdown
Author

Could somebody please take a look at this?

schani and others added 2 commits July 9, 2026 15:47
Only conflict was the import block in Kotlin/language.ts: kept master's
ESM .js import paths and re-added the PR's type imports
(PrimitiveStringTypeKind, TransformedStringTypeKind, StringTypeMapping)
in the same style.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@schani

schani commented Jul 12, 2026

Copy link
Copy Markdown
Member

Update on the CI failures: the fresh run on 379134e confirmed two defects in the feature, and while fixing them we found a third:

  1. Klaxon generation crash (masked in CI by fail-fast): matchType in KotlinKlaxonRenderer.ts is missing the transformedStringType matcher, so generating from test/inputs/schema/date-time.schema dies with "Unsupported type date-time in non-exhaustive match".
  2. Jackson runtime failure (the one CI shows): the generated mapper can't deserialize java.time.LocalDate — nothing handling java.time is registered.
  3. Duplicate union guards in both renderers: when branches like is TextNode -> ... repeated per date type, so only the first union member could ever parse.

We've prepared verified fixes for all three (round-trip byte-identical for both klaxon and jackson locally, fail-case correctly rejected, no regression on non-date output): nikhilunni#1 targets your master, so merging it on your side updates this PR and should turn kotlin CI green. Cherry-picking works too (branch: glideapps/quicktype:kotlin-datetime-fixes-2845) — or say the word and we'll push directly to this PR.

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.

Kotlin date and datetime types are generated as strings from json schema

2 participants