-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Omitted elements when unmarshalling types with same name in different namespaces #83
Comments
May be related to #50. Normally the mapping should refer to |
Hi, here is an example, ground.xsd imports house.xsd and garden.xsd schemas, where in each there is a LocaType type in their own namespace. Then there is the ground.xml instance of ground.xsd, ground.json the unmarshalled json and groudroundtrip.xml as the output of unmarshalling and marshalling. ground.js is the mapping of ground.xsd. ground.xsd : <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
xmlns:ns1="hieu_a" xmlns:h1="urban" xmlns:h2="rural">
<xs:import namespace="urban" schemaLocation="./house.xsd"/>
<xs:import namespace="rural" schemaLocation="./garden.xsd"/>
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="House">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="localisation" type="h1:LocaType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Garden">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element name="localisation" type="h2:LocaType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
house.xsd : <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="urban" xmlns:ns1="urban">
<xs:element name="localisation" type="ns1:LocaType"> </xs:element>
<xs:complexType name="LocaType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="oldName" type="xs:string"/>
<xs:element name="streetName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
garden.xsd : <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
targetNamespace="rural" xmlns:ns2="rural">
<xs:element name="localisation" type="ns2:LocaType"> </xs:element>
<xs:complexType name="LocaType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="swingCount" type="xs:int"/>
<xs:element name="kennelCount" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
ground.xml : <?xml version="1.0" encoding="utf-8"?>
<Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="./ground.xsd">
<House>
<id>
1
</id>
<localisation>
<name>
Kleber
</name>
<oldName>
Kleb
</oldName>
<street>
MainStreet
</street>
</localisation>
</House>
<Garden>
<id>
2
</id>
<localisation>
<name>
Versailles
</name>
<swingCount>
3
</swingCount>
<kennelCount>
5
</kennelCount>
</localisation>
</Garden>
</Root> ground.json {
"name": {
"namespaceURI": "",
"localPart": "Root",
"prefix": "",
"key": "Root",
"string": "Root"
},
"value": {
"TYPE_NAME": "ground.Root",
"house": {
"TYPE_NAME": "ground.Root.House",
"id": 1,
"localisation": {
"TYPE_NAME": "ground.LocaType"
}
},
"garden": {
"TYPE_NAME": "ground.Root.Garden",
"id": 2,
"localisation": {
"TYPE_NAME": "ground.LocaType"
}
}
}
} groudroundtrip.xml : <Root>
<House>
<id>1</id>
<localisation/>
</House>
<Garden>
<id>2</id>
<localisation/>
</Garden>
</Root> ground.js: var ground_Module_Factory = function () {
var ground = {
name: 'ground',
typeInfos: [{
localName: 'Root.House',
propertyInfos: [{
name: 'id',
elementName: {
localPart: 'id'
},
typeInfo: 'Int'
}, {
name: 'localisation',
elementName: {
localPart: 'localisation'
},
typeInfo: '.LocaType'
}]
}, {
localName: 'LocaType',
propertyInfos: [{
name: 'name',
elementName: {
localPart: 'name',
namespaceURI: 'urban'
}
}, {
name: 'oldName',
elementName: {
localPart: 'oldName',
namespaceURI: 'urban'
}
}, {
name: 'streetName',
elementName: {
localPart: 'streetName',
namespaceURI: 'urban'
}
}]
}, {
localName: 'Root',
propertyInfos: [{
name: 'house',
elementName: {
localPart: 'House'
},
typeInfo: '.Root.House'
}, {
name: 'garden',
elementName: {
localPart: 'Garden'
},
typeInfo: '.Root.Garden'
}]
}, {
localName: 'LocaType',
propertyInfos: [{
name: 'name',
elementName: {
localPart: 'name',
namespaceURI: 'rural'
}
}, {
name: 'swingCount',
elementName: {
localPart: 'swingCount',
namespaceURI: 'rural'
},
typeInfo: 'Int'
}, {
name: 'kennelCount',
elementName: {
localPart: 'kennelCount',
namespaceURI: 'rural'
},
typeInfo: 'Int'
}]
}, {
localName: 'Root.Garden',
propertyInfos: [{
name: 'id',
elementName: {
localPart: 'id'
},
typeInfo: 'Int'
}, {
name: 'localisation',
elementName: {
localPart: 'localisation'
},
typeInfo: '.LocaType'
}]
}],
elementInfos: [{
elementName: {
localPart: 'localisation',
namespaceURI: 'urban'
},
typeInfo: '.LocaType'
}, {
elementName: {
localPart: 'Root'
},
typeInfo: '.Root'
}, {
elementName: {
localPart: 'localisation',
namespaceURI: 'rural'
},
typeInfo: '.LocaType'
}]
};
return {
ground: ground
};
};
if (typeof define === 'function' && define.amd) {
define([], ground_Module_Factory);
}
else {
var ground_Module = ground_Module_Factory();
if (typeof module !== 'undefined' && module.exports) {
module.exports.ground = ground_Module.ground;
}
else {
var ground = ground_Module.ground;
}
} |
Thank you for the very detailed report. I've reproduced it. The problem is that your mapping has So from the two When your original XML is parsed, you don't get contents in
|
You must have compiled with |
To sum up, this does not seem to be a problem in Jsonix, but rather in Jsonix Schema Compiler. highsource/jsonix-schema-compiler#41 You have the following options:
I've created a "support" project to demonstrate the third options: https://github.com/highsource/jsonix-support/blob/master/issues/issue-83/bindings/bindings.xjb With generated mappings, tests go through: https://github.com/highsource/jsonix/tree/master/nodejs/scripts/tests/GH83 I'm closing this as this is not a Jsonix issue and there's a workaround. |
Yesterday I had another look at the jsonix schema compiler documentation and indeed tried without the -p options and successfully tested a round trip marshalling with our 84 schemas catalog on all our samples. I was about to close the issue, thanks for the explanation I will also look at the bindings options. |
Hi,
I use Jsonix with a big collection of schemas. I create a mapping module for each xsd where an xml will be instantiated from. Those xsd import "common" xsd files, and sometime they use a type with the same name in different common xsd (so in different namespaces) and in those case the unmarshalled json will have omitted elements in the elements of the name that are common.
For example a schema A imports schemas B and C (of namespaces b and c) and both contains a type of name "CommonType", schema A uses both b:CommonType and c:CommonType. b:CommonType have the elements "Common" and "B" and c:CommonType have the elements "Common" and "C" . So it seems the unmarshalled json will contain the Common node in b:CommonType and c:CommonType, elements but not their exclusive elements "B" and "C".
So if type have the same name in different namespace, it seems jsonix can't disambiguate them.
I am trying to create a simple reproducible example I can share; but maybe I just did something wrong with the mapping or config.
Thanks.
The text was updated successfully, but these errors were encountered: