Skip to content

YAML input containing .nan fails with “Malformed numeric value” before JSON Schema validation #1228

Description

@af851574-oss

Description

When validating YAML input that contains the YAML 1.1 floating-point literal .nan, validation fails with a JsonParseException: Malformed numeric value '.nan' before any JSON Schema rules are applied. This occurs because Jackson’s YAML parser (used internally by this library) does not accept .nan as a valid numeric literal, even though it is permitted by YAML 1.1.

Example

Given this schema:

{
  "type": "object",
  "properties": {
    "defaultValue": { "type": "number" }
  }
}

Yaml input

defaultValue: .nan

Code example

    fun validateYaml(yaml: String, schema: JsonNode) {
        val violatedRules = registry
            .getSchema(schema)
            .validate(yaml, InputFormat.YAML) { executionContext ->
                executionContext.executionConfig {
                    it.formatAssertionsEnabled(true)
                }
            }
            .joinToString("\n")

        require(violatedRules.isNotBlank()) {
            "Validation failed:\n$violatedRules"
        }
    }

    companion object {
        private val registry = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12)
    }

Result

java.io.UncheckedIOException: Invalid input
Caused by: com.fasterxml.jackson.core.JsonParseException:
Malformed numeric value '.nan'

Expected Behavior

.nan should be parsed as a numeric value (NaN) and then validated against the schema.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions