use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.
the class RecordUtil method convertToString.
/**
* @param args
*/
public static String convertToString(Object obj) {
try {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(obj, writer);
return writer.toString();
} catch (JAXBException e) {
return ("Unable to unmarshal because: " + e);
}
}
use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.
the class OrcidMessage method marshall.
private static String marshall(Object obj) throws JAXBException {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
StringWriter writer = new StringWriter();
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(obj, writer);
return writer.toString();
}
use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.
the class ValidateV2SamplesTest method marshall.
private void marshall(Object object, String path) throws JAXBException, SAXException, URISyntaxException {
JAXBContext context = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = context.createMarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(path).toURI()));
marshaller.setSchema(schema);
marshaller.marshal(object, System.out);
}
use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.
the class ValidateV2_1IdentifiersTest method marshallToDOM.
/** Marshals to a DOM
*
* @param type
* @param obj
* @return
*/
private Source marshallToDOM(Class<?> type, Object obj) throws JAXBException, ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
JAXBContext context = JAXBContext.newInstance(type);
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(obj, document);
DOMSource source = new DOMSource(document);
return source;
}
use of javax.xml.bind.Marshaller in project ORCID-Source by ORCID.
the class ValidateV2RC3SamplesTest method marshall.
private void marshall(Object object, String path) throws JAXBException, SAXException, URISyntaxException {
JAXBContext context = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = context.createMarshaller();
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(new File(getClass().getResource(path).toURI()));
marshaller.setSchema(schema);
marshaller.marshal(object, System.out);
}
Aggregations