@SuppressWarnings("rawtypes") public static <T>T fromObject(Object json,Class<T> t){
  if (json instanceof String) {
    Gson g=new Gson();
    return g.fromJson((String)json,t);
  }
 else   if (json instanceof Reader) {
    Gson g=new Gson();
    return g.fromJson((Reader)json,t);
  }
 else   if (json instanceof byte[]) {
    Gson g=new Gson();
    byte[] b1=(byte[])json;
    return g.fromJson(new String(b1),t);
  }
 else   if (json instanceof Map) {
    try {
      Map m=(Map)json;
      T t1=t.newInstance();
      Field[] fs=t.getDeclaredFields();
      for (      Field f : fs) {
        String name=f.getName();
        if (m.containsKey(name)) {
          f.setAccessible(true);
          f.set(t1,m.get(name));
        }
      }
      return t1;
    }
 catch (    Exception e) {
      log.error(json,e);
    }
  }
  return null;
}

@ SuppressWarnings ( "rawtypes" ) public static < T > T fromObject ( Object json , Class < T > t ) { if ( json instanceof String ) { Gson g = new Gson ( ) ; return g . fromJson ( ( String ) json , t ) ; } else if ( json instanceof Reader ) { Gson g = new Gson ( ) ; return g . fromJson ( ( Reader ) json , t ) ; } else if ( json instanceof byte [ ] ) { Gson g = new Gson ( ) ; byte [ ] b1 = ( byte [ ] ) json ; return g . fromJson ( new String ( b1 ) , t ) ; } else if ( json instanceof Map ) { try { Map m = ( Map ) json ; T t1 = t . newInstance ( ) ; Field [ ] fs = t . getDeclaredFields ( ) ; for ( Field f : fs ) { String name = f . getName ( ) ; if ( m . containsKey ( name ) ) { f . setAccessible ( true ) ; f . set ( t1 , m . get ( name ) ) ; } } return t1 ; } catch ( Exception e ) { log . error ( json , e ) ; } } return null ; }
parse the json object to class object
