Skip to content

Commit e3492ae

Browse files
committed
added support for an element of type CDATA to be marshalled as a CDATA section instead of a regular XML element
1 parent acf975a commit e3492ae

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

dist/Jsonix-all.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,10 @@ Jsonix.Binding.Marshalls.Element = Jsonix.Class({
18801880
}
18811881
}
18821882
var typeInfo = actualTypeInfo || declaredTypeInfo;
1883-
if (typeInfo) {
1883+
1884+
if (typeInfo === Jsonix.Schema.XSD.CDATA.INSTANCE) {
1885+
typeInfo.marshal(elementValue.value, context, output, scope);
1886+
} else if (typeInfo) {
18841887
output.writeStartElement(elementValue.name);
18851888
if (actualTypeInfo && declaredTypeInfo !== actualTypeInfo) {
18861889
var xsiTypeName = actualTypeInfo.typeName;
@@ -6087,6 +6090,7 @@ Jsonix.Context = Jsonix
60876090
Jsonix.Schema.XSD.Boolean.INSTANCE,
60886091
Jsonix.Schema.XSD.Byte.INSTANCE,
60896092
Jsonix.Schema.XSD.Calendar.INSTANCE,
6093+
Jsonix.Schema.XSD.CDATA.INSTANCE,
60906094
Jsonix.Schema.XSD.DateAsDate.INSTANCE,
60916095
Jsonix.Schema.XSD.Date.INSTANCE,
60926096
Jsonix.Schema.XSD.DateTimeAsDate.INSTANCE,
@@ -6128,8 +6132,7 @@ Jsonix.Context = Jsonix
61286132
Jsonix.Schema.XSD.UnsignedByte.INSTANCE,
61296133
Jsonix.Schema.XSD.UnsignedInt.INSTANCE,
61306134
Jsonix.Schema.XSD.UnsignedLong.INSTANCE,
6131-
Jsonix.Schema.XSD.UnsignedShort.INSTANCE,
6132-
Jsonix.Schema.XSD.CDATA.INSTANCE ],
6135+
Jsonix.Schema.XSD.UnsignedShort.INSTANCE ],
61336136
CLASS_NAME : 'Jsonix.Context'
61346137
});
61356138

dist/Jsonix-min.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,14 +752,15 @@ var v=undefined;
752752
if(u.supportXsiType&&Jsonix.Util.Type.exists(q.value)){var r=u.getTypeInfoByValue(q.value);
753753
if(r&&r.typeName){v=r
754754
}}var m=v||p;
755-
if(m){t.writeStartElement(q.name);
755+
if(m===Jsonix.Schema.XSD.CDATA.INSTANCE){m.marshal(q.value,u,t,l)
756+
}else{if(m){t.writeStartElement(q.name);
756757
if(v&&p!==v){var n=v.typeName;
757758
var s=Jsonix.Schema.XSD.QName.INSTANCE.print(n,u,t,l);
758759
t.writeAttribute(Jsonix.Schema.XSI.TYPE_QNAME,s)
759760
}if(Jsonix.Util.Type.exists(q.value)){m.marshal(q.value,u,t,l)
760761
}t.writeEndElement()
761762
}else{throw new Error("Element ["+q.name.key+"] is not known in this context, could not determine its type.")
762-
}},getTypeInfoByElementName:function(f,e,g){var h=e.getElementInfo(f,g);
763+
}}},getTypeInfoByElementName:function(f,e,g){var h=e.getElementInfo(f,g);
763764
if(Jsonix.Util.Type.exists(h)){return h.typeInfo
764765
}else{return undefined
765766
}}});
@@ -2467,7 +2468,7 @@ return this.prefixNamespaces[b]
24672468
var f=this.namespacePrefixes[e];
24682469
if(Jsonix.Util.Type.isString(f)){return f
24692470
}else{return d
2470-
}},builtinTypeInfos:[Jsonix.Schema.XSD.AnyType.INSTANCE,Jsonix.Schema.XSD.AnySimpleType.INSTANCE,Jsonix.Schema.XSD.AnyURI.INSTANCE,Jsonix.Schema.XSD.Base64Binary.INSTANCE,Jsonix.Schema.XSD.Boolean.INSTANCE,Jsonix.Schema.XSD.Byte.INSTANCE,Jsonix.Schema.XSD.Calendar.INSTANCE,Jsonix.Schema.XSD.DateAsDate.INSTANCE,Jsonix.Schema.XSD.Date.INSTANCE,Jsonix.Schema.XSD.DateTimeAsDate.INSTANCE,Jsonix.Schema.XSD.DateTime.INSTANCE,Jsonix.Schema.XSD.Decimal.INSTANCE,Jsonix.Schema.XSD.Double.INSTANCE,Jsonix.Schema.XSD.Duration.INSTANCE,Jsonix.Schema.XSD.Float.INSTANCE,Jsonix.Schema.XSD.GDay.INSTANCE,Jsonix.Schema.XSD.GMonth.INSTANCE,Jsonix.Schema.XSD.GMonthDay.INSTANCE,Jsonix.Schema.XSD.GYear.INSTANCE,Jsonix.Schema.XSD.GYearMonth.INSTANCE,Jsonix.Schema.XSD.HexBinary.INSTANCE,Jsonix.Schema.XSD.ID.INSTANCE,Jsonix.Schema.XSD.IDREF.INSTANCE,Jsonix.Schema.XSD.IDREFS.INSTANCE,Jsonix.Schema.XSD.Int.INSTANCE,Jsonix.Schema.XSD.Integer.INSTANCE,Jsonix.Schema.XSD.Language.INSTANCE,Jsonix.Schema.XSD.Long.INSTANCE,Jsonix.Schema.XSD.Name.INSTANCE,Jsonix.Schema.XSD.NCName.INSTANCE,Jsonix.Schema.XSD.NegativeInteger.INSTANCE,Jsonix.Schema.XSD.NMToken.INSTANCE,Jsonix.Schema.XSD.NMTokens.INSTANCE,Jsonix.Schema.XSD.NonNegativeInteger.INSTANCE,Jsonix.Schema.XSD.NonPositiveInteger.INSTANCE,Jsonix.Schema.XSD.NormalizedString.INSTANCE,Jsonix.Schema.XSD.Number.INSTANCE,Jsonix.Schema.XSD.PositiveInteger.INSTANCE,Jsonix.Schema.XSD.QName.INSTANCE,Jsonix.Schema.XSD.Short.INSTANCE,Jsonix.Schema.XSD.String.INSTANCE,Jsonix.Schema.XSD.Strings.INSTANCE,Jsonix.Schema.XSD.TimeAsDate.INSTANCE,Jsonix.Schema.XSD.Time.INSTANCE,Jsonix.Schema.XSD.Token.INSTANCE,Jsonix.Schema.XSD.UnsignedByte.INSTANCE,Jsonix.Schema.XSD.UnsignedInt.INSTANCE,Jsonix.Schema.XSD.UnsignedLong.INSTANCE,Jsonix.Schema.XSD.UnsignedShort.INSTANCE,Jsonix.Schema.XSD.CDATA.INSTANCE],CLASS_NAME:"Jsonix.Context"});
2471+
}},builtinTypeInfos:[Jsonix.Schema.XSD.AnyType.INSTANCE,Jsonix.Schema.XSD.AnySimpleType.INSTANCE,Jsonix.Schema.XSD.AnyURI.INSTANCE,Jsonix.Schema.XSD.Base64Binary.INSTANCE,Jsonix.Schema.XSD.Boolean.INSTANCE,Jsonix.Schema.XSD.Byte.INSTANCE,Jsonix.Schema.XSD.Calendar.INSTANCE,Jsonix.Schema.XSD.CDATA.INSTANCE,Jsonix.Schema.XSD.DateAsDate.INSTANCE,Jsonix.Schema.XSD.Date.INSTANCE,Jsonix.Schema.XSD.DateTimeAsDate.INSTANCE,Jsonix.Schema.XSD.DateTime.INSTANCE,Jsonix.Schema.XSD.Decimal.INSTANCE,Jsonix.Schema.XSD.Double.INSTANCE,Jsonix.Schema.XSD.Duration.INSTANCE,Jsonix.Schema.XSD.Float.INSTANCE,Jsonix.Schema.XSD.GDay.INSTANCE,Jsonix.Schema.XSD.GMonth.INSTANCE,Jsonix.Schema.XSD.GMonthDay.INSTANCE,Jsonix.Schema.XSD.GYear.INSTANCE,Jsonix.Schema.XSD.GYearMonth.INSTANCE,Jsonix.Schema.XSD.HexBinary.INSTANCE,Jsonix.Schema.XSD.ID.INSTANCE,Jsonix.Schema.XSD.IDREF.INSTANCE,Jsonix.Schema.XSD.IDREFS.INSTANCE,Jsonix.Schema.XSD.Int.INSTANCE,Jsonix.Schema.XSD.Integer.INSTANCE,Jsonix.Schema.XSD.Language.INSTANCE,Jsonix.Schema.XSD.Long.INSTANCE,Jsonix.Schema.XSD.Name.INSTANCE,Jsonix.Schema.XSD.NCName.INSTANCE,Jsonix.Schema.XSD.NegativeInteger.INSTANCE,Jsonix.Schema.XSD.NMToken.INSTANCE,Jsonix.Schema.XSD.NMTokens.INSTANCE,Jsonix.Schema.XSD.NonNegativeInteger.INSTANCE,Jsonix.Schema.XSD.NonPositiveInteger.INSTANCE,Jsonix.Schema.XSD.NormalizedString.INSTANCE,Jsonix.Schema.XSD.Number.INSTANCE,Jsonix.Schema.XSD.PositiveInteger.INSTANCE,Jsonix.Schema.XSD.QName.INSTANCE,Jsonix.Schema.XSD.Short.INSTANCE,Jsonix.Schema.XSD.String.INSTANCE,Jsonix.Schema.XSD.Strings.INSTANCE,Jsonix.Schema.XSD.TimeAsDate.INSTANCE,Jsonix.Schema.XSD.Time.INSTANCE,Jsonix.Schema.XSD.Token.INSTANCE,Jsonix.Schema.XSD.UnsignedByte.INSTANCE,Jsonix.Schema.XSD.UnsignedInt.INSTANCE,Jsonix.Schema.XSD.UnsignedLong.INSTANCE,Jsonix.Schema.XSD.UnsignedShort.INSTANCE],CLASS_NAME:"Jsonix.Context"});
24712472
// Complete Jsonix script is included above
24722473
return { Jsonix: Jsonix };
24732474
};

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Binding/Marshalls.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ Jsonix.Binding.Marshalls.Element = Jsonix.Class({
1515
}
1616
}
1717
var typeInfo = actualTypeInfo || declaredTypeInfo;
18-
if (typeInfo) {
18+
19+
if (typeInfo === Jsonix.Schema.XSD.CDATA.INSTANCE) {
20+
typeInfo.marshal(elementValue.value, context, output, scope);
21+
} else if (typeInfo) {
1922
output.writeStartElement(elementValue.name);
2023
if (actualTypeInfo && declaredTypeInfo !== actualTypeInfo) {
2124
var xsiTypeName = actualTypeInfo.typeName;

scripts/src/main/javascript/org/hisrc/jsonix/Jsonix/Context.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ Jsonix.Context = Jsonix
2525
Jsonix.Util.Ensure.ensureObject(options);
2626
if (Jsonix.Util.Type
2727
.isObject(options.namespacePrefixes)) {
28-
this.namespacePrefixes =
28+
this.namespacePrefixes =
2929
Jsonix.Util.Type.cloneObject(options.namespacePrefixes, {});
3030
}
3131
if (Jsonix.Util.Type
3232
.isBoolean(options.supportXsiType)) {
33-
this.supportXsiType = options.supportXsiType;
33+
this.supportXsiType = options.supportXsiType;
3434
}
3535
}
36-
36+
3737
// Initialize prefix/namespace mapping
3838
for (var ns in this.namespacePrefixes)
3939
{
@@ -62,7 +62,7 @@ Jsonix.Context = Jsonix
6262
module = mapping;
6363
} else {
6464
mapping = Jsonix.Util.Type.cloneObject(mapping);
65-
module = new this.mappingStyle.module(mapping,
65+
module = new this.mappingStyle.module(mapping,
6666
{
6767
mappingStyle : this.mappingStyle
6868
});
@@ -259,6 +259,7 @@ Jsonix.Context = Jsonix
259259
Jsonix.Schema.XSD.Boolean.INSTANCE,
260260
Jsonix.Schema.XSD.Byte.INSTANCE,
261261
Jsonix.Schema.XSD.Calendar.INSTANCE,
262+
Jsonix.Schema.XSD.CDATA.INSTANCE,
262263
Jsonix.Schema.XSD.DateAsDate.INSTANCE,
263264
Jsonix.Schema.XSD.Date.INSTANCE,
264265
Jsonix.Schema.XSD.DateTimeAsDate.INSTANCE,
@@ -302,4 +303,4 @@ Jsonix.Context = Jsonix
302303
Jsonix.Schema.XSD.UnsignedLong.INSTANCE,
303304
Jsonix.Schema.XSD.UnsignedShort.INSTANCE ],
304305
CLASS_NAME : 'Jsonix.Context'
305-
});
306+
});

typescript/src/main/typescript/Jsonix.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Unmarshaller { //TODO: <T> @see createUnmarshaller
1414

1515
/**
1616
* (description)
17-
*
17+
*
1818
* @param {string} fileName (description)
1919
* @param {(unmarshalled:Object)=> void} callback (description)
2020
* @param {Object} options (description)
@@ -24,7 +24,7 @@ interface Unmarshaller { //TODO: <T> @see createUnmarshaller
2424

2525
/**
2626
* (description)
27-
*
27+
*
2828
* @param {string} url (description)
2929
* @param {(unmarshalled:Object)=> void} callback (description)
3030
* @param {Object} options (description)
@@ -33,7 +33,7 @@ interface Unmarshaller { //TODO: <T> @see createUnmarshaller
3333

3434
/**
3535
* (description)
36-
*
36+
*
3737
* @param {Element} doc (description)
3838
* @param {string} scope (description)
3939
* @returns {Object} (description)
@@ -48,15 +48,15 @@ interface Unmarshaller { //TODO: <T> @see createUnmarshaller
4848
interface Marshaller { // TODO: generics like marshalString(object:T):string;
4949
/**
5050
* (description)
51-
*
51+
*
5252
* @param {Object} object (description)
5353
* @returns {string} (description)
5454
*/
5555
marshalString(object: Object): string;
5656

5757
/**
5858
* (description)
59-
*
59+
*
6060
* @param {Object} object (description)
6161
* @returns {Element} (description)
6262
*/
@@ -121,6 +121,7 @@ declare module Jsonix {
121121
Boolean: { INSTANCE: {} },
122122
Byte: { INSTANCE: {} },
123123
Calendar: { INSTANCE: {} },
124+
CDATA: { INSTANCE: {} },
124125
DateAsDate: { INSTANCE: {} },
125126
Date: { INSTANCE: {} },
126127
DateTimeAsDate: { INSTANCE: {} },
@@ -298,4 +299,4 @@ interface ClassInfo extends TypeInfo, Styled {
298299
value: { v }
299300
}
300301

301-
}
302+
}

0 commit comments

Comments
 (0)