No String-Argument Constructor/Factory Method to Deserialize from String Value ('')

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

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.

Jackson MismatchedInputException : no String-argument constructor/factory method to deserialize from String value

The exception thrown by Jackson is really quite misleading.

You need to tell Jackson that your sequence of
<advertiser> ...</advertiser> elements is not wrapped
by an additional XML element.
You do this in your Advertisers class
by annotating the List<Advertiser> property with

@JacksonXmlElementWrapper(useWrapping = false)

See also the javadoc of JacksonXmlElementWrapper.useWrapping.

(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('12')

You do not need Students wrapper class. Deserialise this XML payload as List<Student>:

CollectionType studentsListType = xmlMapper.getTypeFactory().constructCollectionType(List.class, Student.class);
List<Student> students = xmlMapper.readValue(xmlFile, studentsListType);

Jackson: "(although at least one Creator exists): no String-argument constructor/factory method to deserialize"

Consider using @Jacksonized annotation with @Builder as per

https://projectlombok.org/features/experimental/Jacksonized

Fix your json object as well as it is malformed. "Errors" is using array of objects, so you should have something like:

{
"errors": [{
"message": "bla bla bla"
}]
}

no String-argument constructor/factory method to deserialize from String value ('E1')

The problem stands in the use of the global module.setDefaultUseWrapper(false) in your deserialization while the use of the DefaultUseWrapper should be limited to the nested collection List<Employee> employee in your Company class with the @JacksonXmlElementWrapper(useWrapping = false) like below:

@JacksonXmlRootElement
public class Company {

@JacksonXmlProperty(localName = "Employee")
@JacksonXmlElementWrapper(useWrapping = false)
private List<Employee> employee;

...other fields, setters, getters and constructors from your code
}

You have to delete the module.setDefaultUseWrapper(false) and rewrite your main class like below:

JacksonXmlModule module = new JacksonXmlModule();
XmlMapper objectMapper = new XmlMapper(module);
Company company = objectMapper.readValue(xml,Company.class);
System.out.println(objectMapper.writeValueAsString(company));

no String-argument constructor/factory method to deserialize from String value ('http://localhost:8080/categories/1')

The problem is that a category field is a Categorie type but you are receiving a String.

It should be:

    {
"titre": "my titre8",
"description": "my descr8",
"realisateur": "realisateur8",
"categorie": {
"id": 1,
"name": "XX"
}
}


Related Topics



Leave a reply



Submit