[英]Why is Jackson throwing a 'Cannot deserialize value of type `...` from Object value (token `JsonToken.START_OBJECT`)' when using with Scala?
I start with the following working code...我从以下工作代码开始......
val source = scala.io.Source.fromFile(path)
val after = try source.mkString finally source.close()
val mapper: CsvMapper = new CsvMapper()
val it: MappingIterator[util.List[String]] =
mapper.readerForListOf(classOf[String])
.withFeatures(CsvParser.Feature.WRAP_AS_ARRAY)
.readValues(after);
it.readAll().forEach(item => {
println(item)
})
Now instead of a set of strings I want to use the first row as the headers and then map the other rows.现在我想使用第一行而不是一组字符串作为标题,然后使用 map 其他行。 I create my model object like...
我创建了我的 model object 之类的......
@JsonIgnoreProperties(ignoreUnknown = true)
class ManagedUnit {
@JsonProperty("Unit Name") val unitName: String = null
def getUnitName(): String = unitName
}
And then try to change the parser...然后尝试更改解析器...
val source = scala.io.Source.fromFile(path)
val after = try source.mkString finally source.close()
val mapper: CsvMapper = new CsvMapper()
val schema: CsvSchema =
mapper.typedSchemaFor(classOf[ManagedUnit])
.withHeader()
.withColumnReordering(true)
val it: MappingIterator[ManagedUnit] =
mapper.readerForListOf(classOf[ManagedUnit])
.`with`(schema)
.readValues(after);
it.readAll().forEach(item => {
println(item)
})
But when I run I get...但是当我跑步时,我得到...
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type
java.util.ArrayList<com.purepm.data.model.appfolio.ManagedUnit>
from Object value (tokenJsonToken.START_OBJECT
)Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type
java.util.ArrayList<com.purepm.data.model.appfolio.ManagedUnit>
from Object value (tokenJsonToken.START_OBJECT
)
readerForListOf
should have been readerWithTypedSchemaFor
readerForListOf
应该是readerWithTypedSchemaFor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.