Flat buffers : Object serialization must not be nested

痴心易碎 提交于 2019-12-02 10:53:06

问题


        FlatBufferBuilder fbb = new FlatBufferBuilder(1024);

        String directory = "/Users/samarnath/RmsOne/CreateFlatBuffer/src/com/rms/objects/resources";
        File [] policyfiles = ReturnFilesWithPattern(directory, "singlecoverriskpolicy");

        for (File file: policyfiles)
        {

            Long StructureId = 0L;
            int insurer = 0;
            int insured = 0;
            int UnderWriter = 0;
            int inception = 0;
            int Expiration = 0;
            int ExternalID = 0;
            Long SubjectId =0L;
            int SubjectName = 0;
            int SubjectStructureName = 0;
            int Share = 0;
            Double blanketLimit = 0.0;
            Double attachment = 0.0;
            int causeofLoss = 0;
            int maxDeductible = 0;
            int attachmentCurrency = 0;
            int offset= 0;
            int deductibleCurrencyOffset = 0;
            int createOffset =0;
            int blanketLimitCurrency = 0;


            String folderName = "nfs://dev-spark-share.lab.rmsonecloud.net/mnt/data/UserData/import/outputfiles/Job_5/SmokeTest_2M/eufl_only_client4_2_edm__20151203-134544__24/contract/";
            List<String> lines = Files.readAllLines(file.toPath());
            List<String> actualLines = lines.subList(1, lines.size());

            for (String line:actualLines)
            {
                String [] riskitems = line.split("~");

                SingleCoverRiskPolicy.startSingleCoverRiskPolicy(fbb);
                Long Id  = Long.parseLong(riskitems[0]);
                int policyName = fbb.createString(riskitems[1]);

After the above line i get an error saying Exception in thread "main" java.lang.AssertionError: FlatBuffers: object serialization must not be nested.I get an error in fbb.createString.

The code is simple and i cant figure out whats wrong here


回答1:


From the documentation: "Everything else (other tables, strings, vectors) MUST be created before the start of the table they are referenced in."

So move int policyName = fbb.createString(riskitems[1]) and any other strings/vectors/tables you reference in SingleCoverRiskPolicy to before startSingleCoverRiskPolicy.



来源:https://stackoverflow.com/questions/34729894/flat-buffers-object-serialization-must-not-be-nested

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!