Skip to content

YAML file with no content throws MismatchedInputException when binding to Object type (POJO etc) -- add YAMLReadFeature.EMPTY_DOCUMENT_AS_EMPTY_OBJECT #154

Description

@serandel

A curious behaviour I've encountered adding Jackson to a Kotlin project...

I'm trying to deserialize a YAML file to a Kotlin data class

data class Settings(val wireframe: Boolean = false)

with the following code

mapper = ObjectMapper(YAMLFactory())
mapper.registerModule(KotlinModule()) 

val settings = settingsFileInputStream.use {
   mapper.readValue(it, Settings::class.java)
}

If the file content is

wireframe: true

it works.

But if I comment out the settings like this:

#wireframe: true

then I get the following exception:

com.fasterxml.jackson.databind.exc.MismatchedInputException: No content to map due to end-of-input

I believed it was because default parameters in the data class weren't accepted, but no. To prove that, I modified the settings like this:

data class Settings(val wireframe: Boolean = false, val foo: String = "bar")

and I can deserialize from this file:

#wireframe: true
foo: foobar

but I get the exception again if I use

#wireframe: true
#foo: foobar

Jackson version: 2.9.10 (latest stable, AFAIK)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    yamlIssue related to YAML format backend

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions