8

When I try to serialize object containing Local date, I get following error:

csv generator does not support object values for properties

I have JSR-310 module enabled, with WRITE_DATES_AS_TIMESTAMPS and I can convert the same object to JSON without problem.

For now I resorted to mapping the object to another, string only object, but it's decadent and wasteful.

Is there a way for Jackson csv mapper to acknowledge localDates? Should I somehow enable JSR-310 specifically for csv mapper?

charlie_pl
  • 2,898
  • 4
  • 25
  • 39

1 Answers1

14

I had the same problem because of configuring mapper after schema. Make sure you are using the latest verson of jackson and its modules. This code works for me:

final CsvMapper mapper = new CsvMapper();
mapper.findAndRegisterModules();
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); //Optional
final CsvSchema schema = mapper.schemaFor(PojoWithLocalDate.class);
// Use this mapper and schema as you need to: get readers, writers etc.

No additional annotations needed in Pojo class.

  • Congratulations on your first accepted answer! Keep up the good work. – charlie_pl May 25 '17 at 06:33
  • 1
    some important things I have noticed : 1) findAndRegisterModules is required, otherwise the error will persist 2) mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) can be replaced by Mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) 3) confirmed that no annotations are needed in Pojo class – epol Sep 03 '20 at 15:37