J'essaie d'utiliser Realm mobile platform
où j'appelle le service Web externe du serveur d'objet de domaine et crée des objets de différentes entités.La propriété de type 'array' a un type d'objet inconnu dans le serveur d'objet de domaine
après avoir créé le schéma quand je suis des données de dumping dans ce que je reçois l'erreur suivante
Schema validation failed due to the following errors:
- Property 'Response.customersList' of type 'array' has unknown object type 'Customer'
ici est mon code
'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!");
});
Ce n'est pas du code 'java'. S'il vous plaît corriger vos tags. –