Package com.browseengine.bobo.serialize.JSONSerializable

Examples of com.browseengine.bobo.serialize.JSONSerializable.JSONSerializationException


      }
      else if (type==Byte.TYPE){
        Array.setByte(array, index, (byte)jsonArray.getInt(index));
      }
      else{
        throw new JSONSerializationException("Unknown primitive: "+type);
      }
    }
    else if (type==String.class){
      Array.set(array, index, jsonArray.getString(index));
    }
View Full Code Here


        }
        else if (type==Byte.TYPE){
          f.setByte(retObj, (byte)jsonObj.getInt(key));
        }
        else{
          throw new JSONSerializationException("Unknown primitive: "+type);
        }
      }
      else if (type==String.class){
        f.set(retObj, jsonObj.getString(key));
      }
      else if (JSONSerializable.class.isAssignableFrom(type)){
        JSONObject jObj=jsonObj.getJSONObject(key);
        JSONSerializable serObj=deSerialize(type,jObj);
        f.set(retObj, serObj);
      }
    }
    catch(Exception e){
      throw new JSONSerializationException(e.getMessage(),e);
    }
  }
View Full Code Here

 
  public static JSONSerializable deSerialize(Class clz,JSONObject jsonObj) throws JSONSerializationException,JSONException{
    Iterator iter=jsonObj.keys();
   
    if (!JSONSerializable.class.isAssignableFrom(clz)){
      throw new JSONSerializationException(clz+" is not an instance of "+JSONSerializable.class);
    }
   
    JSONSerializable retObj;
    try {
      retObj = (JSONSerializable)clz.newInstance();
    } catch (Exception e1) {
      throw new JSONSerializationException("trouble with no-arg instantiation of "+clz.toString()+
          ": "+e1.getMessage(),e1);
    }
   
    if (JSONExternalizable.class.isAssignableFrom(clz)){
      ((JSONExternalizable)retObj).fromJSON(jsonObj);
      return retObj;
    }
   
   
    while(iter.hasNext()){
      String key=(String)iter.next();

      try {
        Field f=clz.getDeclaredField(key);
        if (f!=null){
          f.setAccessible(true);
          Class type=f.getType();
         
          if (type.isArray()){
            JSONArray array=jsonObj.getJSONArray(key);
            int len=array.length();
            Class cls=type.getComponentType();
           
            Object newArray=Array.newInstance(cls, len);
            for (int k=0;k<len;++k){
              loadObject(newArray,cls,k,array);
            }
            f.set(retObj, newArray);
          }
          else{
            loadObject(retObj,f,jsonObj);
          }
        }
      } catch (Exception e) {
        throw new JSONSerializationException(e.getMessage(),e);
      }
    }
   
    return retObj;
  }
View Full Code Here

  private static void dumpObject(JSONObject jsonObj,Field f,JSONSerializable srcObj) throws JSONSerializationException,JSONException{
    Object value;
    try {
      value = f.get(srcObj);
    } catch (Exception e) {
      throw new JSONSerializationException(e.getMessage(),e);
    }
   
    Class type=f.getType();
   
    String name=f.getName();
View Full Code Here

          }
          else{
            dumpObject(jsonObj,fields[i],obj);
          }
        } catch (Exception e) {
          throw new JSONSerializationException(e.getMessage(),e);
        }
      }
    }
   
    return jsonObj;
View Full Code Here

TOP

Related Classes of com.browseengine.bobo.serialize.JSONSerializable.JSONSerializationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.