1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package com.opencsv.bean.mocks;
17
18 import com.opencsv.bean.AbstractBeanField;
19 import com.opencsv.exceptions.CsvDataTypeMismatchException;
20
21
22
23
24
25
26 public class ConverterComplexClassForCustomAnnotation<T, I> extends AbstractBeanField<T, I> {
27
28 @Override
29 protected Object convert(String value) {
30 ComplexClassForCustomAnnotation o;
31 String[] sa = value.split("\\.", 3);
32 if (sa[2].contains("derived")) {
33 o = new ComplexDerivedClassForCustomAnnotation();
34 ((ComplexDerivedClassForCustomAnnotation) o).f = (float) 1.0;
35 } else if (sa[2].contains("badtype")) {
36 return "Mismatched data type";
37 } else {
38 o = new ComplexClassForCustomAnnotation();
39 }
40 o.i = Integer.parseInt(sa[0]);
41 o.c = sa[1].charAt(0);
42 o.s = sa[2];
43 return o;
44 }
45
46 @Override
47 protected String convertToWrite(Object o) throws CsvDataTypeMismatchException {
48 if(!(o instanceof ComplexClassForCustomAnnotation)) {
49 throw new CsvDataTypeMismatchException();
50 }
51 ComplexClassForCustomAnnotation c = (ComplexClassForCustomAnnotation)o;
52 StringBuilder sb = new StringBuilder();
53 sb.append(c.i).append('.');
54 sb.append(c.c).append('.');
55 sb.append(c.s);
56 return sb.toString();
57 }
58 }