title: super csv nested bean
body: <p>I have a csv </p>
  
  <pre><code>id,name,description,price,date,name,address
  1,SuperCsv,Write csv file,1234.56,28/03/2016,amar,jp nagar
  </code></pre>
  
  <p>I want to read it and store it to json file.
  I have created two bean course(id,name,description,price,date) and person(name,address)</p>
  
  <p>on reading by bean reader i'm not able to set the person address.
  The (beautified) output is </p>
  
  <pre><code>Course [id=1,
          name=SuperCsv,
          description=Write csv file,
          price=1234.56,
          date=Mon Mar 28 00:00:00 IST 2016,
          person=[
              Person [name=amar, address=null],
              Person [name=null, address=jpnagar]
          ]
  ]
  </code></pre>
  
  <p>I want the adress to set with name</p>
  
  <p>My code:</p>
  
  <pre><code>public static void readCsv(String csvFileName) throws IOException {
  
          ICsvBeanReader beanReader = null;
          try {
              beanReader = new CsvBeanReader(new FileReader(csvFileName), CsvPreference.STANDARD_PREFERENCE);
  
              // the header elements are used to map the values to the bean (names must match)
              final String[] header = beanReader.getHeader(true);
              final CellProcessor[] processors = getProcessors();
  
              final String[] fieldMapping = new String[header.length];
  
              for (int i = 0; i &lt; header.length; i++) {
                  if (i &lt; 5) {
                      // normal mappings
                      fieldMapping[i] = header[i];
  
                  } else {
                      // attribute mappings
                      fieldMapping[i] = "addAttribute";
  
                  }}
              ObjectMapper mapper=new ObjectMapper();
              Course course;
              List&lt;Course&gt; courseList=new ArrayList&lt;Course&gt;();
              while ((course = beanReader.read(Course.class, fieldMapping, processors)) != null) {
                  // process course
                  System.out.println(course);
                  courseList.add(course);
  
  
              }
  private static CellProcessor[] getProcessors(){
  
          final CellProcessor parsePerson = new CellProcessorAdaptor() {
              public Object execute(Object value, CsvContext context) {
                  return new Person((String) value,null);
              }
          };  
  
          final CellProcessor parsePersonAddress = new CellProcessorAdaptor() {
              public Object execute(Object value, CsvContext context) {
                  return new Person(null,(String) value);
              }
          };
  
          return new CellProcessor[] {
                  new ParseInt(),
                  new NotNull(),
                  new Optional(),
                  new ParseDouble(),
                  new ParseDate("dd/MM/yyyy"),
                  new Optional(parsePerson),
                  new Optional(parsePersonAddress)        
          };
  </code></pre>