use of org.eclipse.persistence.jaxb.JAXBMarshaller in project eclipselink by eclipse-ee4j.
the class DefaultNamespace2TestCases method testObjectToXMLStreamWriterRepairingRecord.
public void testObjectToXMLStreamWriterRepairingRecord() throws Exception {
if (XML_OUTPUT_FACTORY != null) {
StringWriter writer = new StringWriter();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
Object objectToWrite = getWriteControlObject();
XMLDescriptor desc = null;
if (objectToWrite instanceof XMLRoot) {
desc = (XMLDescriptor) xmlContext.getSession(0).getProject().getDescriptor(((XMLRoot) objectToWrite).getObject().getClass());
} else {
desc = (XMLDescriptor) xmlContext.getSession(0).getProject().getDescriptor(objectToWrite.getClass());
}
jaxbMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/xml");
int sizeBefore = getNamespaceResolverSize(desc);
XMLStreamWriterRecord record = new XMLStreamWriterRecord(streamWriter);
try {
((org.eclipse.persistence.jaxb.JAXBMarshaller) jaxbMarshaller).marshal(objectToWrite, record);
} catch (Exception e) {
assertMarshalException(e);
return;
}
if (expectsMarshalException) {
fail("An exception should have occurred but didn't.");
return;
}
streamWriter.flush();
int sizeAfter = getNamespaceResolverSize(desc);
assertEquals(sizeBefore, sizeAfter);
Document testDocument = getTestDocument(writer.toString());
writer.close();
objectToXMLDocumentTest(testDocument);
}
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project eclipselink by eclipse-ee4j.
the class InheritanceImportsTestCases method getJSONMarshaller.
@Override
protected JAXBMarshaller getJSONMarshaller() throws Exception {
JAXBMarshaller jsonMarshaller = (JAXBMarshaller) jaxbContext.createMarshaller();
jsonMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
Map<String, String> namespaces = new HashMap<String, String>();
namespaces.put("childnamespace", "ns0");
jsonMarshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespaces);
return jsonMarshaller;
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project eclipselink by eclipse-ee4j.
the class JAXBInheritanceNSSeparatorTestCases method getJSONMarshaller.
@Override
public JAXBMarshaller getJSONMarshaller() throws Exception {
JAXBMarshaller m = super.getJSONMarshaller();
m.setProperty(MarshallerProperties.JSON_NAMESPACE_SEPARATOR, '*');
return m;
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project eclipselink by eclipse-ee4j.
the class JAXBInheritanceNSTestCases method getJSONMarshaller.
@Override
public JAXBMarshaller getJSONMarshaller() throws Exception {
Map<String, String> namespaces = new HashMap<String, String>();
namespaces.put("rootNamespace", "ns0");
namespaces.put("someNamespace", "ns1");
namespaces.put(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi");
JAXBMarshaller jsonMarshaller = (JAXBMarshaller) jaxbContext.createMarshaller();
jsonMarshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespaces);
jsonMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
return jsonMarshaller;
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project eclipselink by eclipse-ee4j.
the class JAXBInheritanceSubTypeNoParentRootTestCases method getJSONMarshaller.
@Override
public JAXBMarshaller getJSONMarshaller() throws Exception {
Map<String, String> namespaces = new HashMap<String, String>();
namespaces.put("rootNamespace", "ns0");
namespaces.put("someNamespace", "ns1");
namespaces.put(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi");
JAXBMarshaller jsonMarshaller = (JAXBMarshaller) jaxbContext.createMarshaller();
jsonMarshaller.setProperty(MarshallerProperties.NAMESPACE_PREFIX_MAPPER, namespaces);
jsonMarshaller.setProperty(MarshallerProperties.MEDIA_TYPE, "application/json");
return jsonMarshaller;
}
Aggregations