No String-argument constructor/factory method to deserialize from String value (”)

We Are Going To Discuss About No String-argument constructor/factory method to deserialize from String value (”). So lets Start this Java Article.

No String-argument constructor/factory method to deserialize from String value (”)

  1. No String-argument constructor/factory method to deserialize from String value ('')

    Had this when I accidentally was calling
    mapper.convertValue(...)
    instead of
    mapper.readValue(...)
    So, just make sure you call correct method, since argument are same and IDE can find many things

  2. No String-argument constructor/factory method to deserialize from String value ('')

    Had this when I accidentally was calling
    mapper.convertValue(...)
    instead of
    mapper.readValue(...)
    So, just make sure you call correct method, since argument are same and IDE can find many things

Solution 1

Had this when I accidentally was calling

mapper.convertValue(...)

instead of

mapper.readValue(...)

So, just make sure you call correct method, since argument are same and IDE can find many things

Original Author Andrii Plotnikov Of This Content

Solution 2

Try setting

mapper.configure(
          DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
          true)

or

mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

depending on your Jackson version.

Original Author Abhijit Sarkar Of This Content

Solution 3

This exception says that you are trying to deserialize the object “Address” from string “\”\”” instead of an object description like “{…}”. The deserializer can’t find a constructor of Address with String argument. You have to replace “” by {} to avoid this error.

Original Author papaRomik Of This Content

Solution 4

Use below code snippet This worked for me

ObjectMapper objectMapper = new ObjectMapper();
String jsonString = "{\"symbol\":\"ABCD\}";
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
Trade trade = objectMapper.readValue(jsonString, new TypeReference<Symbol>() {});

Model Class

@JsonIgnoreProperties    public class Symbol {
    @JsonProperty("symbol")
    private String symbol;
}

Original Author Abhilash Ranjan Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment