Java 类com.alibaba.fastjson.JSONStreamAware 实例源码

项目:GitHub    文件:JSONSerializerTest.java   
public void test_4() throws Exception {
    JSONSerializer serializer = new JSONSerializer();
    serializer.write(new JSONStreamAware() {

        public void writeJSONString(Appendable out) throws IOException {
            out.append("abc");
        }
    });

    Assert.assertEquals("abc", serializer.getWriter().toString());
}
项目:boohee_v5.6    文件:JSONStreamAwareSerializer.java   
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
    ((JSONStreamAware) object).writeJSONString(serializer.getWriter());
}
项目:uavstack    文件:JSONStreamAwareSerializer.java   
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.getWriter();

    JSONStreamAware aware = (JSONStreamAware) object;
    aware.writeJSONString(out);
}
项目:itmarry    文件:JSONStreamAwareSerializer.java   
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
    SerializeWriter out = serializer.getWriter();

    JSONStreamAware aware = (JSONStreamAware) object;
    aware.writeJSONString(out);
}
项目:android_http_demo    文件:JSONSerializer.java   
public ObjectSerializer getObjectWriter(Class<?> clazz) {
    ObjectSerializer writer = config.get(clazz);

    if (writer == null) {
        if (Map.class.isAssignableFrom(clazz)) {
            config.put(clazz, MapSerializer.instance);
        } else if (List.class.isAssignableFrom(clazz)) {
            config.put(clazz, ListSerializer.instance);
        } else if (Collection.class.isAssignableFrom(clazz)) {
            config.put(clazz, CollectionSerializer.instance);
        } else if (Date.class.isAssignableFrom(clazz)) {
            config.put(clazz, DateSerializer.instance);
        } else if (JSONAware.class.isAssignableFrom(clazz)) {
            config.put(clazz, JSONAwareSerializer.instance);
        } else if (JSONStreamAware.class.isAssignableFrom(clazz)) {
            config.put(clazz, JSONStreamAwareSerializer.instance);
        } else if (clazz.isEnum() || (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum())) {
            config.put(clazz, EnumSerializer.instance);
        } else if (clazz.isArray()) {
            Class<?> componentType = clazz.getComponentType();
            ObjectSerializer compObjectSerializer = getObjectWriter(componentType);
            config.put(clazz, new ArraySerializer(componentType, compObjectSerializer));
        } else if (Throwable.class.isAssignableFrom(clazz)) {
            config.put(clazz, new ExceptionSerializer(clazz));
        } else if (TimeZone.class.isAssignableFrom(clazz)) {
            config.put(clazz, TimeZoneSerializer.instance);
        } else if (Appendable.class.isAssignableFrom(clazz)) {
            config.put(clazz, AppendableSerializer.instance);
        } else if (Charset.class.isAssignableFrom(clazz)) {
            config.put(clazz, ToStringSerializer.instance);
        } else if (Enumeration.class.isAssignableFrom(clazz)) {
            config.put(clazz, EnumerationSeriliazer.instance);
        } else if (Calendar.class.isAssignableFrom(clazz)) {
            config.put(clazz, CalendarSerializer.instance);
        } else {
            boolean isCglibProxy = false;
            boolean isJavassistProxy = false;
            for (Class<?> item : clazz.getInterfaces()) {
                if (item.getName().equals("net.sf.cglib.proxy.Factory")) {
                    isCglibProxy = true;
                    break;
                } else if (item.getName().equals("javassist.util.proxy.ProxyObject")) {
                    isJavassistProxy = true;
                    break;
                }
            }

            if (isCglibProxy || isJavassistProxy) {
                Class<?> superClazz = clazz.getSuperclass();

                ObjectSerializer superWriter = getObjectWriter(superClazz);
                config.put(clazz, superWriter);
                return superWriter;
            }

            if (Proxy.isProxyClass(clazz)) {
                config.put(clazz, config.createJavaBeanSerializer(clazz));
            } else {
                config.put(clazz, config.createJavaBeanSerializer(clazz));
            }
        }

        writer = config.get(clazz);
    }
    return writer;
}
项目:android_http_demo    文件:JSONStreamAwareSerializer.java   
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
    SerializeWriter out = serializer.getWriter();

    JSONStreamAware aware = (JSONStreamAware) object;
    aware.writeJSONString(out);
}
项目:AndroidNio    文件:JSONSerializer.java   
public ObjectSerializer getObjectWriter(Class<?> clazz) {
    ObjectSerializer writer = config.get(clazz);

    if (writer == null) {
        if (Map.class.isAssignableFrom(clazz)) {
            config.put(clazz, MapSerializer.instance);
        } else if (List.class.isAssignableFrom(clazz)) {
            config.put(clazz, ListSerializer.instance);
        } else if (Collection.class.isAssignableFrom(clazz)) {
            config.put(clazz, CollectionSerializer.instance);
        } else if (Date.class.isAssignableFrom(clazz)) {
            config.put(clazz, DateSerializer.instance);
        } else if (JSONAware.class.isAssignableFrom(clazz)) {
            config.put(clazz, JSONAwareSerializer.instance);
        } else if (JSONStreamAware.class.isAssignableFrom(clazz)) {
            config.put(clazz, JSONStreamAwareSerializer.instance);
        } else if (clazz.isEnum() || (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum())) {
            config.put(clazz, EnumSerializer.instance);
        } else if (clazz.isArray()) {
            Class<?> componentType = clazz.getComponentType();
            ObjectSerializer compObjectSerializer = getObjectWriter(componentType);
            config.put(clazz, new ArraySerializer(componentType, compObjectSerializer));
        } else if (Throwable.class.isAssignableFrom(clazz)) {
            config.put(clazz, new ExceptionSerializer(clazz));
        } else if (TimeZone.class.isAssignableFrom(clazz)) {
            config.put(clazz, TimeZoneSerializer.instance);
        } else if (Appendable.class.isAssignableFrom(clazz)) {
            config.put(clazz, AppendableSerializer.instance);
        } else if (Charset.class.isAssignableFrom(clazz)) {
            config.put(clazz, ToStringSerializer.instance);
        } else if (Enumeration.class.isAssignableFrom(clazz)) {
            config.put(clazz, EnumerationSeriliazer.instance);
        } else if (Calendar.class.isAssignableFrom(clazz)) {
            config.put(clazz, CalendarSerializer.instance);
        } else {
            boolean isCglibProxy = false;
            boolean isJavassistProxy = false;
            for (Class<?> item : clazz.getInterfaces()) {
                if (item.getName().equals("net.sf.cglib.proxy.Factory")) {
                    isCglibProxy = true;
                    break;
                } else if (item.getName().equals("javassist.util.proxy.ProxyObject")) {
                    isJavassistProxy = true;
                    break;
                }
            }

            if (isCglibProxy || isJavassistProxy) {
                Class<?> superClazz = clazz.getSuperclass();

                ObjectSerializer superWriter = getObjectWriter(superClazz);
                config.put(clazz, superWriter);
                return superWriter;
            }

            if (Proxy.isProxyClass(clazz)) {
                config.put(clazz, config.createJavaBeanSerializer(clazz));
            } else {
                config.put(clazz, config.createJavaBeanSerializer(clazz));
            }
        }

        writer = config.get(clazz);
    }
    return writer;
}
项目:AndroidNio    文件:JSONStreamAwareSerializer.java   
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
    SerializeWriter out = serializer.getWriter();

    JSONStreamAware aware = (JSONStreamAware) object;
    aware.writeJSONString(out);
}