title: Using Spring Batch to parse date from file into LocalDateTime
body: <p>I'm trying to read a CSV file with dates with Spring Batch, but I am having trouble parsing a date into a <code>LocalDateTime</code> Object:</p>
  
  <blockquote>
    <p>Field error in object 'target' on field 'date': rejected value [2017-07-20 04:15:25.0]; codes [typeMismatch.target.date,typeMismatch.date,typeMismatch.java.time.LocalDateTime,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [target.date,date]; arguments []; default message [date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'date'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.time.LocalDateTime' for property 'date': no matching editors or conversion strategy found]</p>
  </blockquote>
  
  <p><code>Main.java</code>:</p>
  
  <pre><code>public class Main {
      public static void main(String[] args) {
          ApplicationContext context = new AnnotationConfigApplicationContext(SpringBatchDateParseConfig.class);
  
          JobLauncher jobLauncher = context.getBean(JobLauncher.class);
          Job job = context.getBean("job", Job.class);
  
          JobParameters jobParameters = new JobParametersBuilder().toJobParameters();
  
          try {
              JobExecution jobExecution = jobLauncher.run(job, jobParameters);
          }
          catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p><code>SpringBatchDateParseConfig.java</code>:</p>
  
  <pre><code>@Configuration
  @EnableBatchProcessing
  public class SpringBatchDateParseConfig {
      @Inject
      private JobBuilderFactory jobBuilderFactory;
  
      @Inject
      private StepBuilderFactory stepBuilderFactory;
  
      @Bean
      public Step step1() {
          return stepBuilderFactory.get("step1")
                                   .&lt;TestClass, TestClass&gt;chunk(2)
                                   .reader(testClassItemReader())
                                   .writer(testClassItemWriter())
                                   .build();
      }
  
      @Bean
      public Job job(Step step1) {
          return jobBuilderFactory.get("job")
                  .start(step1)
                  .build();
      }
  
      @Bean
      FlatFileItemReader&lt;TestClass&gt; testClassItemReader() {
          FlatFileItemReader&lt;TestClass&gt; flatFileItemReader = new FlatFileItemReader&lt;&gt;();
          flatFileItemReader.setResource(new ClassPathResource("test.csv"));
          flatFileItemReader.setLinesToSkip(1);
          DefaultLineMapper defaultLineMapper = new DefaultLineMapper();
          DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
          delimitedLineTokenizer.setNames(new String[]{"foo", "bar", "date"});
  
          BeanWrapperFieldSetMapper&lt;TestClass&gt; fieldSetMapper = new BeanWrapperFieldSetMapper&lt;&gt;();
          fieldSetMapper.setTargetType(TestClass.class);
  
          defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
          defaultLineMapper.setFieldSetMapper(fieldSetMapper);
          flatFileItemReader.setLineMapper(defaultLineMapper);
  
          return flatFileItemReader;
  
      }
  
      @Bean
      ItemWriter&lt;TestClass&gt; testClassItemWriter() {
          return new ItemWriter&lt;TestClass&gt;() {
              @Override
              public void write(List&lt;? extends TestClass&gt; items) throws Exception {
                  for (TestClass TestClass : items) {
                      System.out.println(TestClass.toString());
                  }
              }
          };
      }
  }
  </code></pre>
  
  <p><code>TestClass.java</code>:</p>
  
  <pre><code>public class TestClass {
  
      private String foo;
      private String bar;
      @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME, pattern = "yyyy-MM-dd H:m:s.S")
      private LocalDateTime date;
  
      public String getFoo() {
          return foo;
      }
  
      public void setFoo(String foo) {
          this.foo = foo;
      }
  
      public String getBar() {
          return bar;
      }
  
      public void setBar(String bar) {
          this.bar = bar;
      }
  
      public LocalDateTime getDate() {
          return date;
      }
  
      public void setDate(LocalDateTime date) {
          this.date = date;
      }
  }
  </code></pre>
  
  <p><code>test.csv</code>:</p>
  
  <pre><code>foo,bar,date
  asdf,fdsa,2017-07-20 04:15:25.0
  qwerty,ytrewq,2017-07-20 04:15:25.0
  </code></pre>
  
  <p>Am I missing something?</p>