use of org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper in project eclipselink by eclipse-ee4j.
the class XMLWithJSONMappingTestCases method testJSONUnmarshalFromInputSource.
public void testJSONUnmarshalFromInputSource() throws Exception {
if (isUnmarshalTest() && !(platform.name().equals(PLATFORM_DOC_PRES) || platform.name().equals(PLATFORM_DOM))) {
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(controlJSONLocation);
InputSource inputSource = new InputSource(inputStream);
xmlUnmarshaller.setMediaType(MediaType.APPLICATION_JSON);
PrefixMapperNamespaceResolver nr = null;
if (getNamespaces() != null) {
NamespacePrefixMapper mapper = new MapNamespacePrefixMapper(getNamespaces());
nr = new PrefixMapperNamespaceResolver(mapper, null);
xmlUnmarshaller.setNamespaceResolver(nr);
}
Object testObject = xmlUnmarshaller.unmarshal(inputSource);
inputStream.close();
if ((getJSONReadControlObject() instanceof XMLRoot) && (testObject instanceof XMLRoot)) {
XMLRoot controlObj = (XMLRoot) getReadControlObject();
XMLRoot testObj = (XMLRoot) testObject;
compareXMLRootObjects(controlObj, testObj);
} else {
assertEquals(getJSONReadControlObject(), testObject);
}
}
}
use of org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper in project eclipselink by eclipse-ee4j.
the class XMLWithJSONMappingTestCases method testJSONMarshalToOutputStream.
public void testJSONMarshalToOutputStream() throws Exception {
if (!(platform.name().equals(PLATFORM_DOC_PRES) || platform.name().equals(PLATFORM_DOM))) {
xmlMarshaller.setMediaType(MediaType.APPLICATION_JSON);
if (getNamespaces() != null) {
xmlMarshaller.setNamespacePrefixMapper(new MapNamespacePrefixMapper(getNamespaces()));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
xmlMarshaller.marshal(getWriteControlObject(), os);
} catch (Exception e) {
assertMarshalException(e);
return;
}
if (expectsMarshalException) {
fail("An exception should have occurred but didn't.");
return;
}
compareStrings("testJSONMarshalToOutputStream", new String(os.toByteArray()));
os.close();
}
}
use of org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper in project eclipselink by eclipse-ee4j.
the class XMLWithJSONMappingTestCases method testJSONMarshalToStringWriter.
public void testJSONMarshalToStringWriter() throws Exception {
if (!(platform.name().equals(PLATFORM_DOC_PRES) || platform.name().equals(PLATFORM_DOM))) {
xmlMarshaller.setMediaType(MediaType.APPLICATION_JSON);
if (getNamespaces() != null) {
xmlMarshaller.setNamespacePrefixMapper(new MapNamespacePrefixMapper(getNamespaces()));
}
StringWriter sw = new StringWriter();
try {
xmlMarshaller.marshal(getWriteControlObject(), sw);
} catch (Exception e) {
assertMarshalException(e);
return;
}
if (expectsMarshalException) {
fail("An exception should have occurred but didn't.");
return;
}
compareStrings("**testJSONMarshalToStringWriter**", sw.toString());
}
}
use of org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper in project eclipselink by eclipse-ee4j.
the class XMLWithJSONMappingTestCases method testJSONMarshalToStringWriter_FORMATTED.
public void testJSONMarshalToStringWriter_FORMATTED() throws Exception {
if (!(platform.name().equals(PLATFORM_DOC_PRES) || platform.name().equals(PLATFORM_DOM))) {
xmlMarshaller.setMediaType(MediaType.APPLICATION_JSON);
if (getNamespaces() != null) {
xmlMarshaller.setNamespacePrefixMapper(new MapNamespacePrefixMapper(getNamespaces()));
}
xmlMarshaller.setFormattedOutput(true);
StringWriter sw = new StringWriter();
try {
xmlMarshaller.marshal(getWriteControlObject(), sw);
} catch (Exception e) {
assertMarshalException(e);
return;
}
if (expectsMarshalException) {
fail("An exception should have occurred but didn't.");
return;
}
compareStrings("**testJSONMarshalToStringWriter**", sw.toString());
}
}
use of org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper in project eclipselink by eclipse-ee4j.
the class XMLWithJSONMappingTestCases method testJSONMarshalToOutputStream_FORMATTED.
public void testJSONMarshalToOutputStream_FORMATTED() throws Exception {
if (!(platform.name().equals(PLATFORM_DOC_PRES) || platform.name().equals(PLATFORM_DOM))) {
xmlMarshaller.setMediaType(MediaType.APPLICATION_JSON);
if (getNamespaces() != null) {
xmlMarshaller.setNamespacePrefixMapper(new MapNamespacePrefixMapper(getNamespaces()));
}
xmlMarshaller.setFormattedOutput(true);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
xmlMarshaller.marshal(getWriteControlObject(), os);
} catch (Exception e) {
assertMarshalException(e);
return;
}
if (expectsMarshalException) {
fail("An exception should have occurred but didn't.");
return;
}
compareStrings("testJSONMarshalToOutputStream", new String(os.toByteArray()));
os.close();
}
}
Aggregations