Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML multi-document does not work with readValue #132

Closed
chrylis opened this issue May 6, 2019 · 3 comments
Closed

YAML multi-document does not work with readValue #132

chrylis opened this issue May 6, 2019 · 3 comments
Labels
yaml Issue related to YAML format backend

Comments

@chrylis
Copy link

chrylis commented May 6, 2019

Over in #66, a working example is posted for using the SnakeYAML engine to deserialize with Jackson. However, while this works to produce a MappingIterator, the general contract for ObjectMapper#readValue is broken:

ObjectMapper mapper = new ObjectMapper(new YAMLFactory()).findAndRegisterModules()
mapper.readValue(EntitySchema.getResourceAsStream('entitySchemas.yml'), new TypeReference<List<EntitySchema>>() {})

This produces an exception:

Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList` out of START_OBJECT token
 at [Source: (BufferedInputStream); line: 2, column: 1]
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1343)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1139)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1093)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.handleNonArray(CollectionDeserializer.java:332)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:265)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:245)
	at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:27)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3077)
	... 1 more

I'm opening this issue here because it appears to be a case where the ObjectMapper isn't delegating properly when provided with an explicit factory.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-databind May 17, 2019
@cowtowncoder cowtowncoder added the yaml Issue related to YAML format backend label May 17, 2019
@cowtowncoder
Copy link
Member

@chrylis No, this seems to work as intended -- readValue() is limited to a single document and is not designed or intended to support binding over multiple documents. It does not do that for json either (where newline-separated content can be viewed as a sequence of documents.

To read content from multiple logical YAML documents, MappingIterator approach (or a sequence of separate readValue() calls) is needed.

@chrylis
Copy link
Author

chrylis commented May 17, 2019

Okay, I think I can see the data model here, and it makes sense, but it wasn't the obvious interpretation to me. Perhaps a mention of the "multiple documents != single document with a list of objects" model in the documentation would be helpful.

@cowtowncoder
Copy link
Member

@chrylis Yes I totally agree that distinction is not something that is well surfaced, and should be documented better. I think I'll create a doc issue to try to outline this with YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml Issue related to YAML format backend
Projects
None yet
Development

No branches or pull requests

2 participants