Package com.addthis.codec.reflection

Examples of com.addthis.codec.reflection.CodableClassInfo


        }
    }

    // like the one in Fields.java, but non-static and using a possibly non-default registry
    private CodableClassInfo getOrCreateClassInfo(Class<?> clazz) {
        CodableClassInfo fieldMap = fieldMaps.get(clazz);
        if (fieldMap == null) {
            fieldMap = new CodableClassInfo(clazz, pluginRegistry);
            fieldMaps.put(clazz, fieldMap);
        }
        return fieldMap;
    }
View Full Code Here


        }
        try {
            if (object instanceof SuperCodable) {
                ((SuperCodable) object).preEncode();
            }
            CodableClassInfo classInfo = Fields.getClassFieldMap(object.getClass());
            if (classInfo.size() == 0 && !(object instanceof Codable)) {
                return object;
            }
            obj = new JSONObject();
            String altType = classInfo.getClassName(object);
            if (altType != null) {
                obj.put(classInfo.getClassField(), altType);
            }
            for (Iterator<CodableFieldInfo> fields = classInfo.values().iterator(); fields.hasNext();) {
                CodableFieldInfo field = fields.next();
                Object value = field.get(object);
                if (value == null || value == JSONObject.NULL || field.isReadOnly()) {
                    continue;
                }
View Full Code Here

            } catch (NoSuchMethodException | IllegalAccessException ex) {
                throw new IllegalStateException("Attempted to decode enum type", ex);
            }
            return (T) json;
        }
        CodableClassInfo classInfo = Fields.getClassFieldMap(type);

        // json config is "unexpectedly" an array; if the base class has registered a handler, use it
        if (json instanceof JSONArray) {
            Class<?> arrarySugar = classInfo.getArraySugar();
            if (arrarySugar != null) {
                LineNumberInfo infoCopy = ((JSONArray) json).getMyLineNumberInfo();
                JSONObject magicWrapper = new JSONObject();
                magicWrapper.put(classInfo.getPluginMap().arrayField(), json, infoCopy, infoCopy);
                classInfo = Fields.getClassFieldMap(arrarySugar);
                json = magicWrapper;
                type = (Class<T>) arrarySugar;
            }
        }
        if (!(json instanceof JSONObject)) {
            return (T) json;
        }
        JSONObject jsonObj = (JSONObject) json;

        if (info == LineNumberInfo.MissingInfo) {
            info = jsonObj.getLineNumberInfo();
        }

        String classField = classInfo.getClassField();
        String stype = jsonObj.optString(classField, null);
        if ((stype == null) && Modifier.isAbstract(type.getModifiers()) &&
            (jsonObj.length() == 1)) {
            // if otherwise doomed to fail, try supporting "type-value : {...}"  syntax
            stype = jsonObj.keySet().iterator().next();
            jsonObj = jsonObj.getJSONObject(stype);
        }
        try {
            if (stype != null) {
                Class<?> atype = classInfo.getClass(stype);
                classInfo = Fields.getClassFieldMap(atype);
                type = (Class<T>) atype;
                jsonObj.remove(classField);
            }
        } catch (Exception ex) {
View Full Code Here

TOP

Related Classes of com.addthis.codec.reflection.CodableClassInfo

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.