Package org.sf.bee.commons.remoting.jrpc.exceptions.impl

Examples of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException


        JSONObject jso = (JSONObject) o;
        long time;
        try {
            time = jso.getLong("time");
        } catch (JSONException e) {
            throw new UnmarshallException("Could not get the time in date serialiser", e);
        }
        if (jso.has(TAG_JAVACLASS)) {
            try {
                clazz = Class.forName(jso.getString(TAG_JAVACLASS));
            } catch (ClassNotFoundException e) {
                throw new UnmarshallException(e.getMessage(), e);
            } catch (JSONException e) {
                throw new UnmarshallException("Could not find javaClass", e);
            }
        }
        Object returnValue = null;
        if (Date.class.equals(clazz)) {
            returnValue = new Date(time);
        } else if (Timestamp.class.equals(clazz)) {
            returnValue = new Timestamp(time);
        } else if (java.sql.Date.class.equals(clazz)) {
            returnValue = new java.sql.Date(time);
        } else if (java.sql.Time.class.equals(clazz)) {
            returnValue = new Time(time);
        }
        if (returnValue == null) {
            throw new UnmarshallException("invalid class " + clazz);
        }
        state.setSerialized(o, returnValue);
        return returnValue;
    }
View Full Code Here


        int object_id;
        try {
            json_type = jso.getString("JSONRPCType");
            object_id = jso.getInt("objectID");
        } catch (JSONException e) {
            throw new UnmarshallException(e.getMessage(), e);
        }
        if (json_type != null) {
            if ((json_type.equals("Reference")) || (json_type.equals("CallableReference"))) {
                ref = bridge.getReference(object_id);
            }
View Full Code Here

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        if (!this.isCompatible(java_class)) {
            throw new UnmarshallException("not a List");
        }
        JSONArray jsonlist;
        try {
            jsonlist = jso.getJSONArray("list");
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read list: " + e.getMessage(), e);
        }
        if (jsonlist == null) {
            throw new UnmarshallException("list missing");
        }
        int i = 0;
        ObjectMatch m = new ObjectMatch(-1);
        state.setSerialized(o, m);
        try {
            for (; i < jsonlist.length(); i++) {
                m.setMismatch(_ser.tryUnmarshall(state, null, jsonlist.get(i)).max(m).getMismatch());
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        }
        return m;
    }
View Full Code Here

        JSONObject jso = (JSONObject) o;
        String java_class;
        try {
            java_class = jso.getString(TAG_JAVACLASS);
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read javaClass", e);
        }
        if (java_class == null) {
            throw new UnmarshallException("no type hint");
        }
        AbstractList al;
        if (java_class.equals("java.util.List") ||
                java_class.equals("java.util.AbstractList") ||
                java_class.equals("java.util.ArrayList")) {
            al = new ArrayList();
        } else if (java_class.equals("java.util.LinkedList")) {
            al = new LinkedList();
        } else if (java_class.equals("java.util.Vector")) {
            al = new Vector();
        } else {
            throw new UnmarshallException("not a List");
        }

        JSONArray jsonlist;
        try {
            jsonlist = jso.getJSONArray("list");
        } catch (JSONException e) {
            throw new UnmarshallException("Could not read list: " + e.getMessage(), e);
        }
        if (jsonlist == null) {
            throw new UnmarshallException("list missing");
        }
        state.setSerialized(o, al);
        int i = 0;
        try {
            for (; i < jsonlist.length(); i++) {
                al.add(_ser.unmarshall(state, null, jsonlist.get(i)));
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        }
        return al;
    }
View Full Code Here

        try {
            for (; i < jso.length(); i++) {
                m.setMismatch(_ser.tryUnmarshall(state, cc, jso.get(i)).max(m).getMismatch());
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage() + " not found in json object", e);
        }
        return m;
    }
View Full Code Here

                    arr[i] = _ser.unmarshall(state, cc, jso.get(i));
                }
                return arr;
            }
        } catch (UnmarshallException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage(), e);
        } catch (JSONException e) {
            throw new UnmarshallException("element " + i + " " + e.getMessage() + " not found in json object", e);
        }
    }
View Full Code Here

        JSONTokener tok = new JSONTokener(jsonString);
        Object json;
        try {
            json = tok.nextValue();
        } catch (JSONException e) {
            throw new UnmarshallException("couldn't parse JSON", e);
        }
        SerializerState state = new SerializerState();
        return this.unmarshall(state, null, json);
    }
View Full Code Here

        if (clazz == null) {
            clazz = getClassFromHint(json);
        }
        if (clazz == null) {
            throw new UnmarshallException("no class hint");
        }
        if (json == null || json == JSONObject.NULL) {
            if (!clazz.isPrimitive()) {
                return ObjectMatch.NULL;
            }

            throw new UnmarshallException("can't assign null primitive");

        }
        ISerializer s = getSerializer(clazz, json.getClass());
        if (s != null) {
            return s.tryUnmarshall(state, clazz, json);
        }
        // As a last resort, we check if the object is in fact an instance of the
        // desired class. This will typically happen when the parameter is of
        // type java.lang.Object and the passed object is a String or an Integer
        // that is passed verbatim by JSON
        if (clazz.isInstance(json)) {
            return ObjectMatch.SIMILAR;
        }

        throw new UnmarshallException("no match");
    }
View Full Code Here

        if (clazz == null) {
            clazz = getClassFromHint(json);
        }

        if (clazz == null) {
            throw new UnmarshallException("no class hint");
        }
        if (json == null || json == JSONObject.NULL) {
            if (!clazz.isPrimitive()) {
                return null;
            }

            throw new UnmarshallException("can't assign null primitive");
        }
        final Class jsonClass = json.getClass();
        final ISerializer s = this.getSerializer(clazz, jsonClass);
        if (s != null) {
            return s.unmarshall(state, clazz, json);
        }

        // As a last resort, we check if the object is in fact an instance of the
        // desired class. This will typically happen when the parameter is of
        // type java.lang.Object and the passed object is a String or an Integer
        // that is passed verbatim by JSON
        if (clazz.isInstance(json)) {
            return json;
        }


        throw new UnmarshallException("no serializer found that can unmarshall "
                + (jsonClass != null ? jsonClass.getName() : "null") + " to " + clazz.getName());
    }
View Full Code Here

            String className = "(unknown)";
            try {
                className = ((JSONObject) o).getString(TAG_JAVACLASS);
                return ClassUtils.forName(className);
            } catch (Exception e) {
                throw new UnmarshallException("Class specified in javaClass hint not found: " + className, e);
            }
        }
        if (o instanceof JSONArray) {
            JSONArray arr = (JSONArray) o;
            if (arr.length() == 0) {
                throw new UnmarshallException("no type for empty array");
            }
            // return type of first element
            Class compClazz;
            try {
                compClazz = getClassFromHint(arr.get(0));
            } catch (JSONException e) {
                throw (NoSuchElementException) new NoSuchElementException(e.getMessage()).initCause(e);
            }
            try {
                if (compClazz.isArray()) {
                    return ClassUtils.forName("[" + compClazz.getName());
                }
                return ClassUtils.forName("[L" + compClazz.getName() + ";");
            } catch (ClassNotFoundException e) {
                throw new UnmarshallException("problem getting array type", e);
            }
        }
        return o.getClass();
    }
View Full Code Here

TOP

Related Classes of org.sf.bee.commons.remoting.jrpc.exceptions.impl.UnmarshallException

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.