“数组”类型的属性在领域对象服务器中具有未知的对象类型

2023-12-31

我正在尝试使用Realm mobile platform我从领域对象服务器调用外部 Web 服务并创建不同实体的对象。

创建架构后,当我将数据转储到其中时,我收到以下错误

Schema validation failed due to the following errors:
- Property 'Response.customersList' of type 'array' has unknown object type 'Customer'

这是我的代码

'use strict';

    var express = require('express');
    var request = require('request');
    var rp = require('request-promise');
    var Realm = require('realm');
    var app = express();

    class Customer {}
    let CustomerSchema ={

     name: 'Customer',
     primaryKey: 'mCustomerId',
      properties: {
        errorMessage:  {type: 'string', optional: true},
        status:{type: 'string', optional: true},
        address: {type: 'string', optional: true},
        customerNumber: {type: 'string', optional: true},
        city: {type: 'string', optional: true},
        contactId: {type: 'double', optional: true},
        country: {type: 'string', optional: true},
        customerId:{type: 'double', optional: true},
        customerRecordType: {type: 'string', optional: true},
        currency: {type: 'string', optional: true},
        email: {type: 'string', optional: true},
        custGroup: {type: 'string', optional: true},
        invoiceAndDeliveryOnHold: {type: 'string', optional: true},
        estimate: {type: 'string', optional: true},
        fax: {type: 'string', optional: true},
        firstName:{type: 'string', optional: true},
        lastName: {type: 'string', optional: true}, 
        mCustomerId: {type: 'string', default: CreateGuid()},   
        notes: {type: 'string', optional: true},    
        organizationName: {type: 'string', optional: true},
        phoneNumber: {type: 'string', optional: true},
        department: {type: 'string', optional: true},
        parentCompanyId: {type: 'double', optional: true},
        parentCompanyName: {type: 'string', optional: true},
        state: {type: 'string', optional: true},
        totalInvoiced: {type: 'double', optional: true},    
        zipcode: {type: 'string', optional: true},
        customerStatus: {type: 'string', optional: true},
        siteId: {type: 'string', optional: true},
        wareHouseId:{type: 'string', optional: true}
      }
    };

    let ResponseSchema = {
      name: 'Response',
      properties: {
        errorMessage: 'string',
        status: 'string',
        customersList: {type: 'list',objectType:'Customer'}
      }
    };


    app.get('/getMasterData', (req, res) => {  

    console.log("Web service called");

    const options = {  
      method: 'POST',
      uri: 'url',
      body: {
        userName: '4500858',
        password: 'password',
        companyId: 'UST1',
        page: 1,
      },
      headers: {
         'content-type': 'application/json' 
        },
      json: true 

    };

     rp(options)  
      .then(function (response) {


        try{

            var customerList = response.customersList;
            var responseRealm = new Realm({           
              schema: [ResponseSchema]
            });

            // error comes in following block
            responseRealm.write(() => {

                    console.log("inserting");
                    responseRealm.create('Response',response, true);
            });     
        }catch(e){

                console.log("Error 1"+e.message);

        }


      })
      .catch(function (err) {

        console.log( "Error 2"+JSON.stringify(err));

      });


    });

    function initializeSchema(){

         Realm.open({schema: [CustomerSchema, ResponseSchema],
                    schemaVersion: 1,
                    migration: (oldRealm, newRealm) => {

                         console.log("oldRealm "+oldRealm);
                          if (oldRealm.schemaVersion < 1) {


                          }
                     }
            }).then(realm => {
            console.log("Schema open");

            let customers = realm.objects('Customer'); 
            console.log(customers.length);

            for(let i=0;i<customers.length;i++){

                console.log(customers[i].firstName);
            }

        });

    }  

    function CreateGuid() {  

        function _p8(s) {  
          var p = (Math.random().toString(16)+"000000000").substr(2,8);  
          return s ? "-" + p.substr(0,4) + "-" + p.substr(4,4) : p ;  
        }  
        return _p8() + _p8(true) + _p8(true) + _p8();  
    }  

    initializeSchema();

    app.listen(3000, function() {
      console.log("Go!");
    });

问题在于:

var responseRealm = new Realm({
    schema: [ResponseSchema]
});

Response链接到Customer, so CustomerSchema任何时候都必须包含在模式数组中ResponseSchema存在。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“数组”类型的属性在领域对象服务器中具有未知的对象类型 的相关文章

随机推荐

  • 什么时候可以使用 Java 中的浮点类型进行货币计算?

    我了解到我不能使用浮点类型 float double在Java中 进行金钱计算 以及当我需要精确结果时的任何其他计算 我必须使用decimal数字类型 BigDecimal在 Java 中 代替 现在我想知道当我can使用浮点类型 他们提供
  • 使用 Convert.ToDouble 时出现异常

    我正在制作一个库存程序 要求用户输入他们想要购买的不同数量的不同物品 我使用此行将项目数转换为双精度数 以便我可以计算 但出现错误 指出我有未处理的格式异常 输入字符串的格式不正确 我有什么遗漏的吗 itembatteries Conver
  • Python Pandas 使用新的 x 轴进行插值

    我想对以下结构的 Pandas 系列进行插值 X 22 88 3 047 45 75 3 215 68 63 3 328 91 50 3 423 114 38 3 516 137 25 3 578 163 40 3 676 196 08 3
  • Jquery - 模拟点击按钮不触发功能

    Ok 所以我一直在使用 firebug 以及我编写的一些扩展来在我经常使用的网站上创建快捷方式 有件事我不明白为什么它不起作用或为什么它不可能 示例代码
  • 如何删除 mouseleave 上的下一个追加?

    我的代码有问题 当我mouseenter一个元素 一个工具栏被附加到这个元素上 但是当我mouseleave从工具栏到元素 工具栏会再次附加 我怎样才能防止这种重新附加 el on mouseenter function e var too
  • Android Studio 创建密钥库错误

    我想通过 Android Studio 生成签名的 APK 这是我的第一个应用程序 所以我需要创建新的密钥库 但是 当我填写文本框并单击 确定 时 出现错误 消息如下 密钥库已导出 但显示错误让我不敢使用它 创建密钥时出现错误 选择 JAV
  • R - 箱线图中的排序

    我正在尝试制作一系列箱形图R由 2 个因素分组 我已经成功地绘制了图 但我无法将盒子按正确的方向排序 我正在使用的数据场如下所示 Nitrogen Species Treatment 2 G L 3 R M 4 G H 4 B L 2 B
  • 更改/设置 gcloud 操作系统登录用户名?

    这么简单的问题 我正在向我的计算引擎添加一个新帐户 我添加了用户和角色以及所有有趣的东西 现在我想添加 ssh 密钥 我通过运行来执行此操作gcloud compute os login ssh keys add key file 这工作正
  • 如何让 Jest 静默测试抛出的错误

    我正在编写一个测试来断言如果提供了一个 prop 而没有提供另一个 prop 则组件会抛出错误 测试本身通过了 但控制台仍然抱怨未捕获的错误并打印整个堆栈跟踪 有没有办法让 Jest 停止打印此信息 因为它会污染测试运行程序并使其看起来像是
  • 如何使 Maven Javadoc 插件适用于任何 Java 版本

    我正在使用 Maven Javadoc 插件 如下所示
  • Java 中的无效字符常量?

    这是我的代码 import java util Scanner import javax swing JOptionPane import java text DecimalFormat Medium Speed Air 1100 feet
  • 使用 TypeScript 将 JSON(来自 Sentry)转换为 HTML

    我想学习 TypeScript 我有一个由哨兵方法返回的 JSON 字典event from exception Python 我想将其格式化为带有可扩展局部变量以及前后上下文的漂亮 HTML 结果应该大致如下所示 下面是一个 json 示
  • rbind 数据框,重复的行名问题

    虽然在一个文件中允许重复的行 和列 名称matrix 他们不允许在data frame 尝试去rbind 一些具有共同行名称的数据框突出了这个问题 考虑下面的两个数据框 foo data frame a 1 3 b 5 7 rownames
  • 从 C 访问网络数据包中未对齐数据的安全、有效的方法

    我正在用 C 为 ARM9 处理器上的 Linux 编写一个程序 该程序用于访问网络数据包 其中包括一系列标记数据 例如
  • PowerShell 中的子字符串截断字符串长度

    是否可以在 PowerShell 中截断字符串 使用SubString 达到给定的最大字符数 even如果原始字符串已经存在shorter 例如 foreach str in hello good morning hi str subStr
  • 获取 ASP.NET MVC5 WebAPI 令牌有时会失败

    获取 ASP NET MVC5 WebAPI 令牌有时会失败 Code string GetAPITokenSync string username string password string apiBaseUri var token s
  • Pyspark ML - 如何保存管道和 RandomForestClassificationModel

    我无法保存使用 python spark 的 ml 包生成的随机森林模型 gt gt gt rf RandomForestClassifier labelCol label featuresCol features gt gt gt pip
  • 如何计算 docker 限制

    我创建了我的码头工人 Python Flask 如何计算内存和 CPU 的限制 我们是否有一些工具可以在具有不同限制的 docker 上运行性能测试 然后建议设置的最佳限制数字是多少 对于已经在容器内运行的应用程序 您可以使用docker
  • 呈现一个新的视图控制器保留选项卡栏

    我目前正在开发一个支持iOS6 的iPhone应用程序 应用程序的结构有一个 UITabBarController 作为根控制器 并分配了许多视图控制器 其中一个选项卡上有一个带有项目列表的 UITableViewController 当选
  • “数组”类型的属性在领域对象服务器中具有未知的对象类型

    我正在尝试使用Realm mobile platform我从领域对象服务器调用外部 Web 服务并创建不同实体的对象 创建架构后 当我将数据转储到其中时 我收到以下错误 Schema validation failed due to the