Package org.mortbay.util.ajax.JSON

Examples of org.mortbay.util.ajax.JSON.Convertor


        if(context==null)
        {
            Log.warn("No current context for Reference");
            return false;
        }
        Convertor c = context.getParser().getConvertorCache().getConvertor(ref.getClass(), true);
        return c instanceof JSONPojoConvertor && ((JSONPojoConvertor)c).setProps(ref, props)!=0;
    }
View Full Code Here


        return getConvertor(clazz, create, true);
    }

    public Convertor getConvertor(Class<?> clazz, boolean create, boolean addClass)
    {
        Convertor convertor = (Convertor)_convertors.get(clazz.getName());
        if(convertor==null && create)
        {
            convertor = newConvertor(clazz, addClass);
            Convertor existing = _convertors.putIfAbsent(clazz.getName(), convertor);
            if(existing != null)
                convertor = existing;
        }       
        return convertor;
    }
View Full Code Here

        return getConvertor(clazz)!=null;
    }
   
    protected Convertor getConvertor(String className)
    {
        Convertor convertor = (Convertor)_convertors.get(className);
        if(convertor==null)
        {
            Class<?> clazz = StandardJSON.loadClass(className);
            convertor = clazz==null ? UNRESOLVED_CONVERTOR : newConvertor(clazz);
            Convertor existing = _convertors.putIfAbsent(className, convertor);
            if(existing != null)
                convertor = existing;
        }
        return convertor;
    }
View Full Code Here

public class DefaultConvertorCache extends StandardConvertorCache
{
   
    public DefaultConvertorCache()
    {
        final Convertor wrapped = newConvertor(Reference.class);
        addConvertor(Reference.class, new Convertor()
        {
            public Object fromJSON(Map map)
            {
                return wrapped.fromJSON(map);
            }
            public void toJSON(Object obj, Output out)
            {
                getConvertor(obj.getClass(), true).toJSON(obj, out);               
            }           
View Full Code Here

    }
   
    public void toJSON(Object obj, Output out)
    {
        String clsName=obj.getClass().getName();
        Convertor convertor=_json.getConvertorFor(clsName);
        if (convertor==null)
        {
            try
            {
                Class cls=Loader.loadClass(JSON.class,clsName);
                convertor=new JSONPojoConvertor(cls,_fromJSON);
                _json.addConvertorFor(clsName, convertor);
             }
            catch (ClassNotFoundException e)
            {
                e.printStackTrace();
            }
        }
        if (convertor!=null&&obj.getClass()!=Object.class)
        {
            convertor.toJSON(obj, out);
        }
        else
        {
            out.add(obj.toString());
        }
View Full Code Here

    {
        Map map=object;
        String clsName=(String)map.get("class");
        if (clsName!=null)
        {
            Convertor convertor=_json.getConvertorFor(clsName);
            if (convertor==null)
            {
                try
                {
                    Class cls=Loader.loadClass(JSON.class,clsName);
                    convertor=new JSONPojoConvertor(cls);
                    _json.addConvertorFor(clsName, convertor);
                }
                catch (ClassNotFoundException e)
                {
                    e.printStackTrace();
                }
            }
            if (convertor!=null&&!clsName.equals(Object.class.getName()))
            {
                return convertor.fromJSON(object);
            }
        }
        return map;
    }
View Full Code Here

    }
   
    public void toJSON(Object obj, Output out)
    {
        String clsName=obj.getClass().getName();
        Convertor convertor=_json.getConvertorFor(clsName);
        if (convertor==null)
        {
            try
            {
                Class cls=Loader.loadClass(JSON.class,clsName);
                convertor=new JSONPojoConvertor(cls);
                _json.addConvertorFor(clsName, convertor);
             }
            catch (ClassNotFoundException e)
            {
                e.printStackTrace();
            }
        }
        if (convertor!=null&&obj.getClass()!=Object.class)
        {
            convertor.toJSON(obj, out);
        }
        else
        {
            out.add(obj.toString());
        }
View Full Code Here

    {
        Map map=object;
        String clsName=(String)map.get("class");
        if (clsName!=null)
        {
            Convertor convertor=_json.getConvertorFor(clsName);
            if (convertor==null)
            {
                try
                {
                    Class cls=Loader.loadClass(JSON.class,clsName);
                    convertor=new JSONPojoConvertor(cls);
                    _json.addConvertorFor(clsName, convertor);
                }
                catch (ClassNotFoundException e)
                {
                    e.printStackTrace();
                }
            }
            if (convertor!=null&&!clsName.equals(Object.class.getName()))
            {
                return convertor.fromJSON(object);
            }
        }
        return map;
    }
View Full Code Here

TOP

Related Classes of org.mortbay.util.ajax.JSON.Convertor

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.