Java tutorial
//package com.java2s; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.math.BigDecimal; import java.math.BigInteger; import java.text.ParseException; import java.text.SimpleDateFormat; public class Main { private static void setterValue(PropertyDescriptor property, Object mapValue, Object object) throws InvocationTargetException, IllegalAccessException, ParseException { Method setter = property.getWriteMethod(); if (mapValue == null) { setter.invoke(object, mapValue); return; } Class propertyType = property.getPropertyType(); String type = propertyType.getName(); String value = mapValue.toString(); if (type.equals("java.lang.String")) { setter.invoke(object, value); } else if (type.equals("java.lang.Integer")) { setter.invoke(object, Integer.parseInt(value)); } else if (type.equals("java.lang.Long")) { setter.invoke(object, Long.parseLong(value)); } else if (type.equals("java.math.BigDecimal")) { setter.invoke(object, BigDecimal.valueOf(Double.parseDouble(value))); } else if (type.equals("java.math.BigInteger")) { setter.invoke(object, BigInteger.valueOf(Long.parseLong(value))); } else if (type.equals("java.util.Date")) { setter.invoke(object, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(value)); } else if (type.equals("java.lang.Boolean")) { setter.invoke(object, Boolean.valueOf(value)); } else if (type.equals("java.lang.Float")) { setter.invoke(object, Float.parseFloat(value)); } else if (type.equals("java.lang.Double")) { setter.invoke(object, Double.parseDouble(value)); } else if (type.equals("java.lang.byte[]")) { setter.invoke(object, value.getBytes()); } else { setter.invoke(object, value); } } }