Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions dist/Jsonix-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -1618,6 +1618,19 @@ Jsonix.XML.Output = Jsonix.Class({
return node;

},
writeCDATA : function(text) {
var node;
if (Jsonix.Util.Type.isFunction(this.document.createCDATASection)) {
node = this.document.createCDATASection(text);
}
else if (this.xmldom) {
node = this.xmldom.createCDATASection(text);
} else {
throw new Error("Could not create a CDATA section node.");
}
this.peek().appendChild(node);
return node;
},
writeAttribute : function(name, value) {
Jsonix.Util.Ensure.ensureString(value);
Jsonix.Util.Ensure.ensureObject(name);
Expand Down Expand Up @@ -1655,7 +1668,7 @@ Jsonix.XML.Output = Jsonix.Class({
}
this.declareNamespace(namespaceURI, prefix);
}

},
writeNode : function(node) {
var importedNode;
Expand Down Expand Up @@ -1764,7 +1777,7 @@ Jsonix.XML.Output = Jsonix.Class({
if (Jsonix.Util.Type.isString(p))
{
var oldp = nspItem[ns];
// If prefix is already declared and equals the proposed prefix
// If prefix is already declared and equals the proposed prefix
if (p === oldp)
{
// Nothing to do
Expand Down Expand Up @@ -1804,6 +1817,7 @@ Jsonix.XML.Output = Jsonix.Class({
},
CLASS_NAME : "Jsonix.XML.Output"
});

Jsonix.Mapping = {};
Jsonix.Mapping.Style = Jsonix.Class({
marshaller : null,
Expand Down Expand Up @@ -1866,6 +1880,7 @@ Jsonix.Binding.Marshalls.Element = Jsonix.Class({
}
}
var typeInfo = actualTypeInfo || declaredTypeInfo;

if (typeInfo) {
output.writeStartElement(elementValue.name);
if (actualTypeInfo && declaredTypeInfo !== actualTypeInfo) {
Expand Down Expand Up @@ -2145,32 +2160,32 @@ Jsonix.Model.ClassInfo = Jsonix
var n = mapping.name||mapping.n||undefined;
Jsonix.Util.Ensure.ensureString(n);
this.name = n;

var ln = mapping.localName||mapping.ln||null;
this.localName = ln;

var dens = mapping.defaultElementNamespaceURI||mapping.dens||mapping.targetNamespace||mapping.tns||'';
this.defaultElementNamespaceURI = dens;

var tns = mapping.targetNamespace||mapping.tns||mapping.defaultElementNamespaceURI||mapping.dens||this.defaultElementNamespaceURI;
this.targetNamespace = tns;

var dans = mapping.defaultAttributeNamespaceURI||mapping.dans||'';
this.defaultAttributeNamespaceURI = dans;

var bti = mapping.baseTypeInfo||mapping.bti||null;
this.baseTypeInfo = bti;

var inF = mapping.instanceFactory||mapping.inF||undefined;
if (Jsonix.Util.Type.exists(inF)) {
// TODO: should we support instanceFactory as functions?
// For the pure JSON configuration?
Jsonix.Util.Ensure.ensureFunction(inF);
this.instanceFactory = inF;
}

var tn = mapping.typeName||mapping.tn||undefined;

if (Jsonix.Util.Type.exists(tn))
{
if (Jsonix.Util.Type.isString(tn))
Expand All @@ -2185,14 +2200,14 @@ Jsonix.Model.ClassInfo = Jsonix
{
this.typeName = new Jsonix.XML.QName(tns, ln);
}

this.properties = [];
this.propertiesMap = {};
var ps = mapping.propertyInfos||mapping.ps||[];
Jsonix.Util.Ensure.ensureArray(ps);
for ( var index = 0; index < ps.length; index++) {
this.p(ps[index]);
}
}
},
getPropertyInfoByName : function(name) {
return this.propertiesMap[name];
Expand Down Expand Up @@ -2237,15 +2252,15 @@ Jsonix.Model.ClassInfo = Jsonix
unmarshal : function(context, input) {
this.build(context);
var result;

if (this.instanceFactory) {
result = new this.instanceFactory();
}
else
{
result = { TYPE_NAME : this.name };
result = { TYPE_NAME : this.name };
}

if (input.eventType !== 1) {
throw new Error("Parser must be on START_ELEMENT to read a class info.");
}
Expand Down Expand Up @@ -2526,6 +2541,7 @@ Jsonix.Model.ClassInfo.prototype.propertyInfoCreators = {
"v" : Jsonix.Model.ClassInfo.prototype.v,
"value" : Jsonix.Model.ClassInfo.prototype.v
};

Jsonix.Model.EnumLeafInfo = Jsonix.Class(Jsonix.Model.TypeInfo, {
name : null,
baseTypeInfo : 'String',
Expand Down Expand Up @@ -2948,6 +2964,9 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
initialize : function(mapping) {
Jsonix.Util.Ensure.ensureObject(mapping);
Jsonix.Model.SingleTypePropertyInfo.prototype.initialize.apply(this, [ mapping ]);

var c = mapping.asCDATA || mapping.c || false;
this.asCDATA = c;
},
unmarshal : function(context, input, scope) {
var text = input.getElementText();
Expand All @@ -2957,7 +2976,12 @@ Jsonix.Model.ValuePropertyInfo = Jsonix.Class(Jsonix.Model.SingleTypePropertyInf
if (!Jsonix.Util.Type.exists(value)) {
return;
}
output.writeCharacters(this.print(value, context, output, scope));

if (this.asCDATA) {
output.writeCDATA(this.print(value, context, output, scope));
} else {
output.writeCharacters(this.print(value, context, output, scope));
}
},
buildStructure : function(context, structure) {
Jsonix.Util.Ensure.ensureObject(structure);
Expand Down Expand Up @@ -5820,15 +5844,15 @@ Jsonix.Context = Jsonix
Jsonix.Util.Ensure.ensureObject(options);
if (Jsonix.Util.Type
.isObject(options.namespacePrefixes)) {
this.namespacePrefixes =
this.namespacePrefixes =
Jsonix.Util.Type.cloneObject(options.namespacePrefixes, {});
}
if (Jsonix.Util.Type
.isBoolean(options.supportXsiType)) {
this.supportXsiType = options.supportXsiType;
this.supportXsiType = options.supportXsiType;
}
}

// Initialize prefix/namespace mapping
for (var ns in this.namespacePrefixes)
{
Expand Down Expand Up @@ -5857,7 +5881,7 @@ Jsonix.Context = Jsonix
module = mapping;
} else {
mapping = Jsonix.Util.Type.cloneObject(mapping);
module = new this.mappingStyle.module(mapping,
module = new this.mappingStyle.module(mapping,
{
mappingStyle : this.mappingStyle
});
Expand Down Expand Up @@ -6098,6 +6122,7 @@ Jsonix.Context = Jsonix
Jsonix.Schema.XSD.UnsignedShort.INSTANCE ],
CLASS_NAME : 'Jsonix.Context'
});

// Complete Jsonix script is included above
return { Jsonix: Jsonix };
};
Expand Down
17 changes: 13 additions & 4 deletions dist/Jsonix-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ if(Jsonix.Util.Type.isFunction(this.document.createTextNode)){d=this.document.cr
}else{throw new Error("Could not create a text node.")
}}this.peek().appendChild(d);
return d
},writeCDATA:function(c){var d;
if(Jsonix.Util.Type.isFunction(this.document.createCDATASection)){d=this.document.createCDATASection(c)
}else{if(this.xmldom){d=this.xmldom.createCDATASection(c)
}else{throw new Error("Could not create a CDATA section node.")
}}this.peek().appendChild(d);
return d
},writeAttribute:function(t,k){Jsonix.Util.Ensure.ensureString(k);
Jsonix.Util.Ensure.ensureObject(t);
var n=t.localPart||t.lp||null;
Expand Down Expand Up @@ -1149,13 +1155,16 @@ Jsonix.Util.Ensure.ensureObject(e.attributes);
var d=this.attributeName.key;
e.attributes[d]=this
},CLASS_NAME:"Jsonix.Model.AttributePropertyInfo"});
Jsonix.Model.ValuePropertyInfo=Jsonix.Class(Jsonix.Model.SingleTypePropertyInfo,{initialize:function(b){Jsonix.Util.Ensure.ensureObject(b);
Jsonix.Model.SingleTypePropertyInfo.prototype.initialize.apply(this,[b])
Jsonix.Model.ValuePropertyInfo=Jsonix.Class(Jsonix.Model.SingleTypePropertyInfo,{initialize:function(d){Jsonix.Util.Ensure.ensureObject(d);
Jsonix.Model.SingleTypePropertyInfo.prototype.initialize.apply(this,[d]);
var c=d.asCDATA||d.c||false;
this.asCDATA=c
},unmarshal:function(e,f,h){var g=f.getElementText();
return this.unmarshalValue(g,e,f,h)
},marshal:function(g,e,f,h){if(!Jsonix.Util.Type.exists(g)){return
}f.writeCharacters(this.print(g,e,f,h))
},buildStructure:function(c,d){Jsonix.Util.Ensure.ensureObject(d);
}if(this.asCDATA){f.writeCDATA(this.print(g,e,f,h))
}else{f.writeCharacters(this.print(g,e,f,h))
}},buildStructure:function(c,d){Jsonix.Util.Ensure.ensureObject(d);
if(Jsonix.Util.Type.exists(d.elements)){throw new Error("The structure already defines element mappings, it cannot define a value property.")
}else{d.value=this
}},CLASS_NAME:"Jsonix.Model.ValuePropertyInfo"});
Expand Down
Loading