Search in sources :

Example 1 with MapNamespacePrefixMapper

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);
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) MapNamespacePrefixMapper(org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper) InputStream(java.io.InputStream) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) PrefixMapperNamespaceResolver(org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver) MapNamespacePrefixMapper(org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper) NamespacePrefixMapper(org.eclipse.persistence.oxm.NamespacePrefixMapper)

Example 2 with MapNamespacePrefixMapper

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();
    }
}
Also used : MapNamespacePrefixMapper(org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with MapNamespacePrefixMapper

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());
    }
}
Also used : MapNamespacePrefixMapper(org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper) StringWriter(java.io.StringWriter) IOException(java.io.IOException)

Example 4 with MapNamespacePrefixMapper

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());
    }
}
Also used : MapNamespacePrefixMapper(org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper) StringWriter(java.io.StringWriter) IOException(java.io.IOException)

Example 5 with MapNamespacePrefixMapper

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();
    }
}
Also used : MapNamespacePrefixMapper(org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

MapNamespacePrefixMapper (org.eclipse.persistence.internal.oxm.record.namespaces.MapNamespacePrefixMapper)6 IOException (java.io.IOException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 StringWriter (java.io.StringWriter)2 NamespacePrefixMapper (org.eclipse.persistence.oxm.NamespacePrefixMapper)2 PropertyException (jakarta.xml.bind.PropertyException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ObjectGraphImpl (org.eclipse.persistence.internal.jaxb.ObjectGraphImpl)1 NamespacePrefixMapperWrapper (org.eclipse.persistence.internal.oxm.record.namespaces.NamespacePrefixMapperWrapper)1 PrefixMapperNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver)1 AbstractSessionLog (org.eclipse.persistence.logging.AbstractSessionLog)1 LogLevel (org.eclipse.persistence.logging.LogLevel)1 SessionLog (org.eclipse.persistence.logging.SessionLog)1 CharacterEscapeHandler (org.eclipse.persistence.oxm.CharacterEscapeHandler)1 MediaType (org.eclipse.persistence.oxm.MediaType)1 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)1 InputSource (org.xml.sax.InputSource)1