I am implementing a service that I used XJC to create the domain classes for from an XSD file. The generated Java I have ported over to grails, but I cannot set XMLAttributes annotations on those fields, well at least I don't know how. How do you do this?
Here's where I am to give an idea:
import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlAttribute
import javax.xml.bind.annotation.XmlType
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "AuditSourceIdentificationType", propOrder = [
"auditSourceTypeCode"
])
class AuditSourceIdentificationType {
static hasMany = [
auditSourceTypeCodes: CodedValue //@XmlElement(name = "AuditSourceTypeCode")?
]
@XmlAttribute(name = "AuditEnterpriseSiteID")
String auditEnterpriseSiteID
@XmlAttribute(name = "AuditSourceID", required = true)
String auditSourceID
}
Any help would be greatly appreciated.
CodePudding user response:
OK I put this down for a few days, which was exactly what was needed. It turns out I was not really thinking about the way the domain classes are really set up, and for some reason I didn't declare the fields as List in addition to placing them in the the hasMany declaration. That is how you set annotations for hasMany fields.
It's been quite awhile since I've set up a grails project, and it really helps to keep up on your practice. Corrected code below:
import javax.xml.bind.annotation.XmlAccessType
import javax.xml.bind.annotation.XmlAccessorType
import javax.xml.bind.annotation.XmlElement
import javax.xml.bind.annotation.XmlRootElement
import javax.xml.bind.annotation.XmlType
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = [
"eventIdentification",
"activeParticipant",
"auditSourceIdentification",
"participantObjectIdentification"
])
@XmlRootElement(name = "AuditMessage")
class AuditMessage {
static hasMany = [
activeParticipants: ActiveParticipant,
auditSourceIdentifications: AuditSourceIdentificationType,
participantObjectIdentifications: ParticipantObjectIdentificationType
]
@XmlElement(name = "ActiveParticipant", required = true)
List activeParticipants
@XmlElement(name = "AuditSourceIdentification", required = true)
List auditSourceIdentifications
@XmlElement(name = "ParticipantObjectIdentification")
List participantObjectIdentifications
String auditMessageText
@XmlElement(name = "EventIdentification", required = true)
EventIdentificationType eventIdentification
}'''