• Register
0 votes
8.9k views

Problem :

I am running into the json parsing issue when using a ObjectMapper class from a com.fasterxml.jackson.databind package, and a error that I am getting is:

com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.graybar.utilities.ups.beans.Address: no String-argument constructor/factory method to deserialize from String value ('')

A web application where this problem is occurring is the Spring MVC application using an AngularJS front end, but I can duplicate a issue with the much smaller, all java program. 

Instead of sending values for the Address bean, I am getting just the empty string. Unfortunately, I am receiving the data from a third party and have no control over a data I receive.

Is there any annotation that needs to be added to be able to remove this issue?

3.9k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

You should try setting mapper.configure(DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true)

Or you can try

mapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);

It depends on the Jackson version.

OR

Had this issue in the recent past. Did lot of research on it and finally found the fix on the issue when I accidentally was calling the

mapper.convertValue(...)

instead of the

mapper.readValue(...)

So, you need to just make sure that you call correct method, since argument are same and IDE can find many things for you.

38.6k points