Jsonix Substitution Groups
by Alexey Valikov
HTML
<script src="https://rawgithub.com/highsource/jsonix/master/dist/Jsonix-all.js"></script>
JavaScript
var MyModule = {
name: 'MyModule',
typeInfos: [{
type: 'classInfo',
localName: 'ElementRefType',
propertyInfos: [{
type: 'element',
name: 'a',
typeInfo: 'String'
}, {
type: 'elementRef',
name: 'b',
typeInfo: 'String'
}]
}],
elementInfos: [{
elementName: 'data',
typeInfo: 'MyModule.ElementRefType'
}, {
elementName: 'c',
substitutionHead: 'b',
typeInfo: 'String'
}]
};
var context = new Jsonix.Context([MyModule]);
var unmarshaller = context.createUnmarshaller();
var unmarshalledB = unmarshaller.unmarshalString('<data><a>1</a><b>2</b></data>');
console.log(unmarshalledB);
var marshaller = context.createMarshaller();
var marshalledB = marshaller.marshalString({
name: {
localPart: 'data'
},
value: {
a: '1',
b: {
name: {
localPart: 'b'
},
value: '2'
}
}
});
console.log(marshalledB);
var unmarshalledC = unmarshaller.unmarshalString('<data><a>1</a><c>2</c></data>');
console.log(unmarshalledC);
var marshalledC = marshaller.marshalString({
name: {
localPart: 'data'
},
value: {
a: '1',
b: {
name: {
localPart: 'c'
},
value: '2'
}
}
});
console.log(marshalledC);