Skip to content

[JavaScript] If Serialized by JS, Deserialized in Java will failed  #703

@3dot141

Description

@3dot141

Describe the bug
rt, i can't use it in js and java.

Expected behavior
if fury support cross platform, the action will be success

To Reproduce
js code

import Fury, {InternalSerializerType,  Type} from '@furyjs/fury';
import * as fs from "fs";

function main1() {

  const description = Type.object("example.bar", {
    c: Type.array(Type.object("example.foo", {
      a: Type.string()
    }))
  });
  const fury = new Fury();
  const {serialize, deserialize} = fury.registerSerializer(description);
  const o = {a: "123"};
  const rawObject = {c: [o, o]}
  console.log(`rawObject: ${JSON.stringify(rawObject)}`);
  const data = serialize({c: [o, o]})

  // create data directory
  if (!fs.existsSync('data')) {
    fs.mkdirSync('data');
  }
  // write data to file 'test.data'
  fs.writeFileSync('data/test.data', data);

  const deserialized = deserialize(data)
  console.log(`deserialized: ${JSON.stringify(deserialized)}`)
}

java code

import cn.hutool.core.io.FileUtil;
import io.fury.Fury;
import io.fury.Language;

/**
 * @author Harrison
 * @since 11.0
 * Created on 2023/7/19
 */
public class FuryTest {
    
    public static class Test {
        
        A[] c;
    }
    
    public static class A {
        
        public String a;
    }
    
    public static void main(String[] args) {
        
        Fury fury = Fury.builder().withLanguage(Language.XLANG)
                .withRefTracking(true)
                .withSecureMode(false)
                .build();
        fury.register(Test.class, "example.bar");
        fury.register(A.class, "example.foo");
        
        byte[] bytes = FileUtil.readBytes("/Users/3dot141/Work/w_source/MagicKit/data/test.data");
        // bytes can be data serialized by other languages.
        
        Test test = new Test();

        A a1 = new A();
        a1.a = "123";
        A a2 = new A();
        a2.a = "123";

        test.c = new A[]{a1, a2};
        byte[] serialize = fury.serialize(test);
        
        Object deserialize = fury.deserialize(bytes);
    ;
        System.out.println();
    
    }
}

Screenshots
image

Environment (please complete the following information):

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions