@@ -383,6 +383,44 @@ ElementHandler.prototype.createElement = function(node) {
383383 return instance ;
384384} ;
385385
386+ /**
387+ * Returns a property with an effective type descriptor,
388+ * in case type is defined through xml -> serialize hint.
389+ *
390+ * @param {any } node parsed
391+ * @param {PropertyDescriptor } property
392+ *
393+ * @return {PropertyDescriptor|null }
394+ */
395+ ElementHandler . prototype . getSerializeAsTypePropertyForNode = function ( node , property ) {
396+
397+ const model = this . model ;
398+
399+ const serializationType = getSerializationType ( property ) ;
400+
401+ if ( ! serializationType ) {
402+ return null ;
403+ }
404+
405+ const elementTypeName = node . attributes [ serializationType ] ;
406+
407+ // type is optional, if it does not exists the
408+ // default type is assumed
409+ if ( elementTypeName ) {
410+
411+ // convert the prefix used to the mapped form, but also
412+ // take possible type prefixes from XML
413+ // into account, i.e.: xsi:type="t{ActualType}",
414+ const normalizedTypeName = normalizeTypeName ( elementTypeName , node . ns , model ) ;
415+
416+ const elementType = model . getType ( normalizedTypeName ) ;
417+
418+ return assign ( { } , property , {
419+ effectiveType : getModdleDescriptor ( elementType ) . name
420+ } ) ;
421+ }
422+ } ;
423+
386424ElementHandler . prototype . getPropertyForNode = function ( node ) {
387425
388426 var name = node . name ;
@@ -398,33 +436,10 @@ ElementHandler.prototype.getPropertyForNode = function(node) {
398436 // search for properties by name first
399437
400438 if ( property && ! property . isAttr ) {
401-
402- const serializationType = getSerializationType ( property ) ;
403-
404- if ( serializationType ) {
405- const elementTypeName = node . attributes [ serializationType ] ;
406-
407- // type is optional, if it does not exists the
408- // default type is assumed
409- if ( elementTypeName ) {
410-
411- // convert the prefix used to the mapped form, but also
412- // take possible type prefixes from XML
413- // into account, i.e.: xsi:type="t{ActualType}",
414- const normalizedTypeName = normalizeTypeName ( elementTypeName , node . ns , model ) ;
415-
416- const elementType = model . getType ( normalizedTypeName ) ;
417-
418- return assign ( { } , property , {
419- effectiveType : getModdleDescriptor ( elementType ) . name
420- } ) ;
421- }
422- }
423-
424- // search for properties by name first
425- return property ;
439+ return this . getSerializeAsTypePropertyForNode ( node , property ) || property ;
426440 }
427441
442+ // search by properties by type
428443 var pkg = model . getPackage ( nameNs . prefix ) ;
429444
430445 if ( pkg ) {
@@ -437,10 +452,11 @@ ElementHandler.prototype.getPropertyForNode = function(node) {
437452 } ) ;
438453
439454 if ( property ) {
440- return assign ( { } , property , {
455+ return this . getSerializeAsTypePropertyForNode ( node , property ) || assign ( { } , property , {
441456 effectiveType : getModdleDescriptor ( elementType ) . name
442457 } ) ;
443458 }
459+
444460 } else {
445461
446462 // parse unknown element (maybe extension)
0 commit comments