Announcement Announcement Module
No announcement yet.
Reading and Writing Beans with custom PropertyEditors Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading and Writing Beans with custom PropertyEditors

    Hi there,

    the idea is simple: read from CSV (text into real types) and write to CSV (types into text).

    For reading i use BeanWrapperFieldSetMapper which gets all configured custom PropertyEditors. This works so far.
    For writing i use BeanWrapperFieldExtractor which should be the opposite to BeanWrapperFieldSetMapper but there is no possibility to assign custom PropertyEditors.

    The editors need to be reconfigured each reading/writing thus i can not configure them globally (using different locales for in/output for example).

    Now i copied the code of BeanWrapperFieldExtractor to assing custom editors to the bean wrapper:

    public Object[] extract(T item) {
    		List<Object> values = new ArrayList<Object>();
    		BeanWrapper bw = new BeanWrapperImpl(item);
    		if (this.customEditors != null) {
    			for (Entry<Class<?>, PropertyEditor> entry : customEditors
    					.entrySet()) {
    				bw.registerCustomEditor(entry.getKey(), entry.getValue());
    But when writing to CSV i get still "toString()" of the property value called instead of "getAsText()" of the PropertyEditor.

    Any idea what i am doing wrong here an how i could i "master" writing the data?

    Thanks in advance