com.jn.agileway.codec.serialization.jdk.JdkCodec Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of agileway-codec Show documentation
Show all versions of agileway-codec Show documentation
Provide an unified codec API for hession, kryo, protostuff, fst, fes, xson, cbor, jackson, json, etc....
package com.jn.agileway.codec.serialization.jdk;
import com.jn.agileway.codec.AbstractCodec;
import com.jn.agileway.codec.CodecException;
import com.jn.langx.util.io.ObjectIOs;
import java.io.IOException;
public class JdkCodec extends AbstractCodec {
@Override
public byte[] encode(T obj) throws CodecException {
try {
return ObjectIOs.serialize(obj);
} catch (IOException ex) {
throw new CodecException(ex.getMessage(), ex);
}
}
@Override
public T decode(byte[] bytes) throws CodecException {
try {
return ObjectIOs.deserialize(bytes);
} catch (Throwable ex) {
throw new CodecException(ex.getMessage(), ex);
}
}
@Override
public T decode(byte[] bytes, Class targetType) throws CodecException {
try {
return ObjectIOs.deserialize(bytes, targetType);
} catch (Throwable ex) {
throw new CodecException(ex.getMessage(), ex);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy