question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

com.fasterxml.jackson.databind.exc.MismatchedInputException: no String-argument constructor/factory method to deserialize from String value

See original GitHub issue

Hi @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:closed
  • Created 6 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
romanchekashovcommented, Aug 26, 2018

I use latest version of lib:

<dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
            <version>2.9.6</version>
        </dependency>

I’ve spent a lot of hours trying to fix this but it doesn’t work for:

<Main>	
	<Something>
		<first cn="abc">someValue</first>
		<second>3050</second>
	</Something>          
	<Something>
		<first>someValue</first>
		<second>3050</second>
	</Something>          
</Main>

If you add:

class First {
    @JacksonXmlProperty(localName = "cn", isAttribute = true)
    private String cn;

    @JacksonXmlText
    private String value;

    @Override
    public String toString() {
        return "[cn: "+cn+" value: "+value+"]";
    }
}

it will throw exception for second element! Both cases with and without attribute just doesn’t work(

0reactions
AnshikaKoulcommented, Jan 28, 2018

hmm, oka.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No String-argument constructor/factory method to deserialize ...
This exception says that you are trying to deserialize the object "Address" from string "\"\"" ...
Read more >
No String-argument constructor/factory method to ... - GitHub
I am trying to deserialise the following xml into the objects: 28 31 My classes are the following public class Foo { private...
Read more >
AWS Lambda ERROR: MismatchedInputException:no String ...
Response $Record` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value.
Read more >
How to map Works JSON Object - Google Groups
I'm having a hard time mapping the works Schema to JSON values using ... no String-argument constructor/factory method to deserialize from ...
Read more >
Jackson Exceptions - Problems and Solutions - Baeldung
When we try to deserialize a JSON String to User, JsonMappingException: No Suitable Constructor Found is thrown:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found