Java Code Examples for com.caucho.hessian.io.AbstractHessianOutput#writeMapEnd()

The following examples show how to use com.caucho.hessian.io.AbstractHessianOutput#writeMapEnd() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericClassSerializer.java    From sofa-hessian with Apache License 2.0 6 votes vote down vote up
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException {
    GenericClass genericClass = (GenericClass) obj;

    if (genericClass == null) {
        out.writeNull();
    } else if (out.addRef(obj)) {
        return;
    } else {
        int ref = out.writeObjectBegin("java.lang.Class");

        if (ref < -1) {
            out.writeString("name");
            out.writeString(genericClass.getClazzName());
            out.writeMapEnd();
        } else {
            if (ref == -1) {
                out.writeInt(1);
                out.writeString("name");
                out.writeObjectBegin("java.lang.Class");
            }

            out.writeString(genericClass.getClazzName());
        }
    }
}
 
Example 2
Source File: GenericMapSerializer.java    From sofa-hessian with Apache License 2.0 6 votes vote down vote up
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException {

        if (out.addRef(obj)) {
            return;
        }

        GenericMap genericMap = (GenericMap) obj;

        out.writeMapBegin(genericMap.getType());

        Iterator iter = genericMap.getMap().entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();

            out.writeObject(entry.getKey());
            out.writeObject(entry.getValue());
        }
        out.writeMapEnd();
    }
 
Example 3
Source File: LocalDateTimeSerializer.java    From jvm-sandbox-repeater with Apache License 2.0 5 votes vote down vote up
@Override
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException {

    if (obj == null) {
        out.writeNull();
    } else {
        Class cl = obj.getClass();

        if (out.addRef(obj)) {
            return;
        }
        // ref 返回-2 便是开始写Map
        int ref = out.writeObjectBegin(cl.getName());

        if (ref < -1) {
            out.writeString("value");
            out.writeUTCDate(((LocalDateTime) obj).toInstant(ZoneOffset.of("+8")).toEpochMilli());
            out.writeMapEnd();
        } else {
            if (ref == -1) {
                out.writeInt(1);
                out.writeString("value");
                out.writeObjectBegin(cl.getName());
            }
            out.writeUTCDate(((LocalDateTime) obj).toInstant(ZoneOffset.of("+8")).toEpochMilli());
        }
    }
}
 
Example 4
Source File: TranscribableEnumSerializer.java    From cougar with Apache License 2.0 5 votes vote down vote up
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException {
    if (out.addRef(obj)) {
        return;
    }

    Class cl = obj.getClass();

    String name = null;
    try {
        name = (String) _name.invoke(obj, (Object[]) null);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // if we're talking to an older version we need to migrate vMajor to vMajor_Minor
    String className = cl.getName();
    if (!transcriptionParams.contains(TranscribableParams.MajorOnlyPackageNaming)) {
        className = ClassnameCompatibilityMapper.toMajorMinorPackaging(cl, _serviceVersion);
    }
    int ref = out.writeObjectBegin(className);

    if (ref < -1) {
        out.writeString("name");
        out.writeString(name);
        out.writeMapEnd();
    }
    else {
        if (ref == -1) {
            out.writeClassFieldLength(1);
            out.writeString("name");
            out.writeObjectBegin(className);
        }

        out.writeString(name);
    }
}