com.fasterxml.jackson.databind.exc.MismatchedInputException: no String-argument constructor/factory method to deserialize from String value
See original GitHub issueHi @cowtowncoder ,
My jackson version 2.9.3:
<jackson.version>2.9.3</jackson.version>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
Kotlin version : <kotlin.version>1.2.10</kotlin.version>
Ratpack version : <ratpack.kotlin.version>1.1.2</ratpack.kotlin.version>
I too am facing an issue while deserialising an element with an attribute.
Example XML that needs to be parsed :
<Something>
<first cn="abc">someValue</first>
<second>3050</second>
</Something>
classes that I am using :
data class Something(
@JacksonXmlProperty(localName = "first", namespace = somenamespace) val first: String
@JacksonXmlProperty(localName = "second", namespace = somenamespace) val second: String
)
class ResponseXmlParser {
private val xmlMapper = xmlObjectMapper()
private val log = LoggerFactory.getLogger(javaClass)
fun parseResponseXml(responseBodyStream: InputStream): Response {
val jsonNode = xmlMapper.readValue(responseBodyStream, Envelope::class.java)
log.info("RESPONSE: " + jsonNode.body.response)
return jsonNode.body.response
}
private fun xmlObjectMapper(): XmlMapper {
val jacksonXmlModule = JacksonXmlModule()
jacksonXmlModule.setDefaultUseWrapper(false)
return XmlMapper(jacksonXmlModule)
.registerModule(KotlinModule())
.registerModule(JavaTimeModule())
.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true) as XmlMapper
}
}
Now in the first element that has both attribute value and textual content. whilst parsing I get this exception:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of com.order.soap.Something
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value (‘3050’)
which is really weird. Coz I have other elements with just attribute value and all of them work just fine. Only this element which has both attribute value and textual content doesn’t work.
I have also posted my comment here : which is related I guess https://github.com/FasterXML/jackson-dataformat-xml/issues/206
Issue Analytics
- State:
- Created 6 years ago
- Comments:20 (8 by maintainers)
Top GitHub Comments
I use latest version of lib:
I’ve spent a lot of hours trying to fix this but it doesn’t work for:
If you add:
it will throw exception for second element! Both cases with and without attribute just doesn’t work(
hmm, oka.