All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jn.agileway.codec.serialization.activejser.ActivejSerCodec Maven / Gradle / Ivy

Go to download

Provide an unified codec API for hession, kryo, protostuff, fst, fes, xson, cbor, jackson, json, etc....

There is a newer version: 3.1.12
Show newest version
package com.jn.agileway.codec.serialization.activejser;

import com.jn.agileway.codec.AbstractCodec;
import com.jn.langx.codec.CodecException;
/**
 * 要求字段得 是 public,
 * 要求必须使用 @Serialize 或者 @Deserialize 注解
 */
public class ActivejSerCodec extends AbstractCodec {

    @Override
    protected byte[] doEncode(T t, boolean withSchema) throws CodecException {
        try {
            return withSchema ? ActivejSerializers.serializeWithSchema(t) : ActivejSerializers.serialize(t);
        } catch (Throwable ex) {
            throw new CodecException(ex);
        }
    }

    @Override
    protected T doDecode(byte[] bytes, boolean withSchema, Class targetType) throws CodecException {
        try {
            return withSchema ? ActivejSerializers.deserializeWithSchema(bytes) : ActivejSerializers.deserialize(bytes, targetType);
        } catch (Throwable ex) {
            throw new CodecException(ex);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy