fury icon indicating copy to clipboard operation
fury copied to clipboard

deserialize failed:After the class with the upstream system itself is serialized, the downstream system can not deserialize without the class object

Open shuyufang opened this issue 1 year ago • 2 comments

Question

public class FurySerializer implements Serializer {

/**
 * fury配置
 */
private static final ThreadSafeFury fury = new FuryBuilder().withLanguage(Language.JAVA)
    .withRefTracking(true)
    .requireClassRegistration(false)
    .withDeserializeNonexistentClass(true)
    .withMetaShare(true)
    .withAsyncCompilation(true)
    .withCompatibleMode(CompatibleMode.COMPATIBLE)
    .withScopedMetaShare(true)
    .withCodegen(true).buildThreadSafeFury();

@Override
public byte[] serialize(Object obj, Integer feature) throws SerializerException {
    try {
        return fury.serializeJavaObject(obj);
    } catch (Exception e) {
        logger.error("[FurySerializer.serialize] exception " + e.getMessage(), e);
        throw new SerializerException(e.toString(), e);
    }
}

@Override
public <T> T deserialize(byte[] bytes, Class<T> cls) throws SerializerException {
    try {
        return fury.deserializeJavaObject(bytes, cls);
    } catch (Exception e) {
        logger.error("[FurySerializer.deserialize] exception " + e.getMessage(), e);
        throw new SerializerException(e.toString(), e);
    }
}

public class FurySerializerTest {

private FurySerializer furySerializer = new FurySerializer();

@Test
public void test() {
    try {
        byte[] byteBuf = new byte[9000];
        // 20241029201856_0B5DEB3A16AD446626A7948A497B9008_84110 Y
        // 20240904171221_212BA390147466B59B7D1320A7820000_84110 F
        String file = "/home/admin/upload/20241029201856_0B5DEB3A16AD446626A7948A497B9008_84110";
        InputStream input = Files.newInputStream(new File(file).toPath());
        int read = IOUtils.read(input, byteBuf);
        System.out.println(read);
        furySerializer.deserialize(byteBuf, AsynMessageRequest.class);
    } catch (Exception e) {
        e.printStackTrace();
    }
    Assert.assertTrue(true);
}

}

image

shuyufang avatar Nov 05 '24 09:11 shuyufang

org.apache.fury fury-core 0.8.0

shuyufang avatar Nov 05 '24 09:11 shuyufang

You can try serialize and deserialize method。For non-existent classes, the corresponding information will be saved in NonexistentClass.NonexistentMetaShared

zhaommmmomo avatar Nov 05 '24 10:11 zhaommmmomo