jackson-dataformat-csv icon indicating copy to clipboard operation
jackson-dataformat-csv copied to clipboard

Support for invalid dates

Open pramodbindal opened this issue 8 years ago • 3 comments

Hi, My input CSV is not controlled by me. it is coming from some upstream server. I need to parse the CSV and there is fair chances for invalid values. Currently If there is any value which is not convertible to target datatype then i get JacksonException. There should be an option to ignore such values and move on to next value.

this is my exception.

at com.fasterxml.jackson.databind.exc.InvalidFormatException.from(InvalidFormatException.java:67) at com.fasterxml.jackson.databind.DeserializationContext.weirdStringException(DeserializationContext.java:1535) at com.fasterxml.jackson.databind.DeserializationContext.handleWeirdStringValue(DeserializationContext.java:910) at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseDate(StdDeserializer.java:523) at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseDate(StdDeserializer.java:466) at com.fasterxml.jackson.databind.deser.std.DateDeserializers$DateBasedDeserializer._parseDate(DateDeserializers.java:195) at com.fasterxml.jackson.databind.deser.std.DateDeserializers$DateDeserializer.deserialize(DateDeserializers.java:285) at com.fasterxml.jackson.databind.deser.std.DateDeserializers$DateDeserializer.deserialize(DateDeserializers.java:268) at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127) at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:287) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151) at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:277)

pramodbindal avatar Sep 12 '17 06:09 pramodbindal

Please register a custom deserializer for such type. It can take whatever action necessary.

cowtowncoder avatar Sep 12 '17 20:09 cowtowncoder

It would be a great help if you can share me an example. I am facing same issue for other data type BigDecimal too

Thanks.

pramodbindal avatar Sep 13 '17 12:09 pramodbindal

@pramodbindal I am sure you can google for "jackson custom deserializers" -- there are many jackson tutorials in existence. In general, here:

https://github.com/FasterXML/jackson-docs

is a list of reported documentation, and I'd be happy to add links to other resources as well.

Deserializers are not format-specific wrt handling (that is, they are registered same way, have same API), so tutorials for json should work as examples.

cowtowncoder avatar Sep 14 '17 04:09 cowtowncoder