saab
saab

Reputation: 139

jsonix: Element [] is not known in this context, could not determine its type

Following instructions on using jsonix-schema-compiler I successfully got an mapping object for a xsd-file; the very summarized content of which is:

var IdentPerson_Module_Factory = function () {
  var IdentPerson = {
    name: 'IdentPerson',
    defaultElementNamespaceURI: 'http:\/\/www.some.domain.de\/mynamespace',
    typeInfos: [{
      ....
      ....
     }],
    elementInfos: [{
        elementName: 'Person',
        typeInfo: '.Person'
     }]
  };
  return {
    IdentPerson: IdentPerson
  };
};

Now I want to produce an xml-String by using jsonix and the above json-mapping-object:

var context = new Jsonix.Context([IdentPerson]);
var marshaller = context.createMarshaller();
var xmldoc = marshaller.marshalString(myJsonString);

First lines of myJsonString are as following:

{ Person:
  { aliasName:
   { titel: '',
     namenssuffix: '',
     familyname: [Object],
 .....
 .....
}

Ending up with the error:

Message:  Element [Person] is not known in this context, could not determine its type.
Stack: Error: Element [Person] is not known in this context, could not determine its type.
at Object.Jsonix.Binding.Marshalls.Element.Jsonix.Class.marshalElement (/home/datarocket/datarocket.hub/src/node_modules/jsonix/jsonix.js:1881:10)

I guess it is because of missing namespace in the myJsonString? If so, how can I fix it? Thanks in advance;

Upvotes: 0

Views: 592

Answers (1)

lexicore
lexicore

Reputation: 43671

Your mapping specifies a namespace but your JSON object does not.

Try:

var context = new Jsonix.Context(mappings, {
    namespacePrefixes: {
        "http://www.some.domain.de/mynamespace": "tns"
    }
});

{ 'tns:Person': ... }

Or:

var context = new Jsonix.Context(mappings, {
    namespacePrefixes: {
        "http://www.some.domain.de/mynamespace": ""
    }
});

{ Person: ... }

Please see documentation on the simplified mapping style, it has a hint for exactly this case.

Disclaimer: I'm the author of Jsonix.

Upvotes: 0

Related Questions