Question

I am using Spring (with Jackson) and jQuery to pass a form as an object. My pojo includes nullable floats. However, when the fields are empty, Jackson throws an Exeption:

org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.lang.Float from String value '': not a valid double value

What do I have to do in order to allow nulls (or empty values in the form field)?

Thanks Er

Was it helpful?

Solution

By default Jackson does indeed only consider explicit JSON null as null value. But if coercion from empty String to null was desired, it's easy to add feature requests. It sounds like a nice improvement actually -- this is how open source projects are often improved, based on user's asking for things they think should be there, ways things should work.

On short term you could also register custom deserializer (http://wiki.fasterxml.com/JacksonHowToCustomDeserializers tells something about it, although is not a guide) that accepts empty String and produces null.

OTHER TIPS

Your best bet is to check for empty string in the javascript code and pass null in that case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top