in runtime/serde/serde-xml/common/src/aws/smithy/kotlin/runtime/serde/xml/XmlSerializer.kt [25:55]
override fun beginStruct(descriptor: SdkFieldDescriptor): StructSerializer {
// if we are serializing a nested structure field
// either through `field(.., SdkSerializable)` or as part of a list member/map entry
// use the parent descriptor instead of the object descriptor passed to us.
// The object descriptor is for root nodes, nested structures have their own field descriptor
// that describes the referred to struct
val structDescriptor = parentDescriptorStack.topOrNull() ?: descriptor
// Serialize top-level (root node) ns declarations and non-default declarations.
val isRoot = nodeStack.isEmpty()
val ns = structDescriptor.findTrait<XmlNamespace>()
if (ns != null && (isRoot || ns.prefix != null)) {
xmlWriter.namespacePrefix(ns.uri, ns.prefix)
}
val tagName = structDescriptor.serialName.name
// if the parent descriptor is from a list or map we omit the root level node
// e.g. Map<String, GreetingStruct> goes to:
// `<value><hi>foo</hi></value>`
// instead of
// `<value><GreetingStruct><hi>foo</hi></GreetingStruct></value>`
//
if (!structDescriptor.isMapOrList) {
xmlWriter.startTag(tagName)
}
nodeStack.push(tagName)
return this
}