Beanプロパティの型変換 (3)

BeanWrapperにRegisterCustomEditorメソッドがあるのを見つけました。これを使えば特定のフィールド(下図では"dateValue")用のプロパティエディタを指定できます。フィールド名をnullにすると、その型のすべてのフィールドに適用されるそうです。

package sample;

import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeanWrapper;

/**
 * Created by IntelliJ IDEA.
 * User: minamoto
 */
public class BeanWrapperTest {
   public static void main(String[] args) throws Exception {
      MyBean3 bean3 = new MyBean3();
      BeanWrapper bw = new BeanWrapperImpl(bean3);
      bw.registerCustomEditor(java.util.Date.class, "dateValue", new MyDateEditor());
      bw.setPropertyValue("dateValue", "2003-11-26");

      System.out.println("bean3 name=" + bean3.getName());
      System.out.println("bean3 dateValue=" + bean3.getDateValue());
   }
}