title: Set value of generic type to DTO field
body: <p>I have a method:    </p>
  
  <pre><code>...
  import java.lang.reflect.Field;
  ...
  
  
  /**
   * @param fieldValue     - value to update with
   * @param fieldClazz     - class of value to update with
   * @param objectToUpdate - object to update
   * @param field          - object's field to update
   */
  private static void setValueToField(String fieldValue,
                                      Class&lt;?&gt; fieldClazz,
                                      Field field, 
                                      Object objectToUpdate)
          throws IllegalAccessException {
      if (Boolean.class.equals(fieldClazz)) {
          field.set(objectToUpdate, Boolean.valueOf(fieldValue));
      } else if (String.class.equals(fieldClazz)) {
          field.set(objectToUpdate, fieldValue);
      } else if (Integer.TYPE.equals(fieldClazz) || Integer.class.equals(fieldClazz)) {
          field.set(objectToUpdate, Integer.parseInt(fieldValue));
      } else if (Long.TYPE.equals(fieldClazz) || Long.class.equals(fieldClazz)) {
          field.set(objectToUpdate, Long.parseLong(fieldValue));
      }
      // todo continue handling different types?
  }
  </code></pre>
  
  <p>It updates field of <code>objectToUpdate</code> with <code>fieldValue</code> represented as String.</p>
  
  <p>Since <code>field</code> of <code>objectToUpdate</code> may be of any class, I have to convert String values of <code>fieldValue</code> to the respective class (which is provided by <code>fieldClazz</code>). But this approach is messy, especially when it comes to nested objects.</p>
  
  <p>Is there a way, perhaps with something like Jackson, to generify this approach? Like "convert String to provided Class" or something.</p>