Closed SirWellington closed 5 years ago
Hey @SirWellington ,
You can achieve that by just wrapping the LastName element in an if
.
xml("Person") {
"FirstName"(person.firstName)
if (person.lastName != null) {
"LastName"(person.lastName)
}
}
Or fancier
xml("Person") {
"FirstName"(person.firstName)
person.lastName?.run { "LastName"(this) }
}
Does that answer your question?
@redundent – Works for me!
Is there any way to use this library with optional elements. So for example, if I have a
name
element that should be added only if the field is optional?lastName=Smith
lastName=null