Je ne suis pas très familier avec Marshaller
mais j'ai essayé dans un projet et le XML
a été généré très bien. Mais quand j'applique le XML validation (with the .xsd file)
il montre une erreur disant que <Timestamp>
est vide. J'ai débogué l'application et je vois que dans mon Bean le Timestamp
est not empty
mais quand le Marshaller
génère le XML il est vraiment vide. D'autre part, d'autres attributs qui utilisent XMLGregorianCalendar
sont présents dans le XML. Je ne sais pas ce qui se passe.Tag d'horodatage vide en XML - Java Marshaller
C'est la fonction du générateur XML:
public void generateXMLReportFile(String fileOutputDirectory,
String xmlOutputFileName,
CRSOECD crsOECD)
throws JAXBException, FileNotFoundException, IOException
{
String encoding = "UTF-8";
// Schema location to write to generated XML file.
String schemaLocation = "urn:oecd:ties:crs:v1 CrsXML_v1.0.xsd";
// Generate The Report:
JAXBContext context = JAXBContext.newInstance(CRSOECD.class);
StringWriter xml = new StringWriter();
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, schemaLocation);
marshaller.marshal(crsOECD, xml);
try (OutputStream out = new FileOutputStream(fileOutputDirectory + xmlOutputFileName)) {
byte[] bytes = xml.toString().getBytes(encoding);
out.write(bytes, 0, bytes.length);
log.info("XML generated.");
}
}
Si je debug, je vois que l'élément qui est vide dans le fichier XML est pas vide dans le Bean crsOECD
.
Quel type actuel 'crsOECD.timestamp' a en classe Java? Peut-être avez-vous besoin d'un convertisseur de type défini dans le fichier bindings.xjb. – Vadim