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
How to Properly Use Enums With Multiple Values
How to Enable Request Scope in Async Task Executor
How to Load 100 Million Rows in to Memory
Error: Incompatible Types: List<Integer> Cannot Be Converted to Arraylist<Integer>
How Is This Wrong - Hackerrank Loop in Java
Requestmethod Post Not Supported || Spring Login
Java 8: How to Write Lambda Stream to Work With Jsonarray
The Group Coordinator Is Not Available-Kafka
How to Set the Timeout for a Jax-Ws Webservice Client
Java Execution Pops a New Window and Immediately Disappears
How to View Apache Parquet File in Windows
Jpa: Update Only Specific Fields
How to Prevent Xss Attacks or Untrusted Data in Rest API Json Using Java
Counting Unique Characters in a String
How to Remove Padding Around Buttons in Android
Mockito Not Mocking Private Variables Using @Spy