不得嵌套对象序列化

不得嵌套对象序列化

本文介绍了平面缓冲区:不得嵌套对象序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        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]);

在上一行之后,我收到一条错误消息,指出主线程" java.lang.AssertionError中的异常:FlatBuffers:对象序列化不能嵌套.在fbb.createString中出现错误.

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

推荐答案

来自文档:必须在引用它们的表开始之前创建所有其他内容(其他表,字符串,向量)."

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

因此,将int policyName = fbb.createString(riskitems[1])和在SingleCoverRiskPolicy中引用的任何其他字符串/向量/表移到startSingleCoverRiskPolicy之前.

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

这篇关于平面缓冲区:不得嵌套对象序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 11:14