Search in sources :

Example 11 with TypeMappingInfo

use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.

the class XmlListTestCases method _testArray.

public void _testArray(Object controlArray) throws Exception {
    XmlList xmlList = new XmlList() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return XmlList.class;
        }
    };
    Annotation[] a = { xmlList };
    TypeMappingInfo t = new TypeMappingInfo();
    t.setType(controlArray.getClass());
    t.setXmlTagName(new QName("root"));
    t.setAnnotations(a);
    TypeMappingInfo[] types = { t };
    JAXBContext jaxbContext = (JAXBContext) JAXBContextFactory.createContext(types, null, Thread.currentThread().getContextClassLoader());
    StringReader stringReader = new StringReader(XML);
    StreamSource streamSource = new StreamSource(stringReader);
    JAXBUnmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement o = unmarshaller.unmarshal(streamSource, t);
    Object testArray = o.getValue();
    assertEquals(Array.get(controlArray, 0), Array.get(testArray, 0));
    assertEquals(Array.get(controlArray, 1), Array.get(testArray, 1));
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    JAXBMarshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    marshaller.marshal(o, streamResult, t);
    assertEquals(XML, stringWriter.toString());
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) JAXBContext(org.eclipse.persistence.jaxb.JAXBContext) JAXBElement(jakarta.xml.bind.JAXBElement) Annotation(java.lang.annotation.Annotation) XmlList(jakarta.xml.bind.annotation.XmlList) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) JAXBUnmarshaller(org.eclipse.persistence.jaxb.JAXBUnmarshaller) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller)

Example 12 with TypeMappingInfo

use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.

the class XmlListTestCases method _testJSONArray.

public void _testJSONArray(Object controlArray, String controlString, String mediaType) throws Exception {
    XmlList xmlList = new XmlList() {

        @Override
        public Class<? extends Annotation> annotationType() {
            return XmlList.class;
        }
    };
    Annotation[] a = { xmlList };
    TypeMappingInfo t = new TypeMappingInfo();
    t.setType(controlArray.getClass());
    t.setXmlTagName(new QName("root"));
    t.setAnnotations(a);
    TypeMappingInfo[] types = { t };
    Map props = new HashMap();
    props.put(JAXBContextProperties.MEDIA_TYPE, mediaType);
    JAXBContext jaxbContext = (JAXBContext) JAXBContextFactory.createContext(types, props, Thread.currentThread().getContextClassLoader());
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    JAXBMarshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    marshaller.marshal(controlArray, streamResult, t);
    assertEquals(removeWhiteSpaceFromString(controlString), removeWhiteSpaceFromString(stringWriter.toString()));
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) JAXBContext(org.eclipse.persistence.jaxb.JAXBContext) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo) HashMap(java.util.HashMap) Map(java.util.Map) JAXBMarshaller(org.eclipse.persistence.jaxb.JAXBMarshaller) Annotation(java.lang.annotation.Annotation) XmlList(jakarta.xml.bind.annotation.XmlList)

Example 13 with TypeMappingInfo

use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.

the class TypeMappingInfoObjectTestCases method getTypeMappingInfos.

protected TypeMappingInfo[] getTypeMappingInfos() throws Exception {
    if (typeMappingInfos == null) {
        typeMappingInfos = new TypeMappingInfo[2];
        TypeMappingInfo tpi = new TypeMappingInfo();
        tpi.setXmlTagName(new QName("someuri", "response"));
        tpi.setElementScope(ElementScope.Global);
        tpi.setType(Object.class);
        typeMappingInfos[0] = tpi;
        TypeMappingInfo tmi = new TypeMappingInfo();
        tmi.setType(Employee.class);
        tmi.setXmlTagName(new QName("someuri", "employee"));
        tmi.setElementScope(ElementScope.Global);
        typeMappingInfos[1] = tmi;
    }
    return typeMappingInfos;
}
Also used : QName(javax.xml.namespace.QName) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo)

Example 14 with TypeMappingInfo

use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.

the class NullStringTestCases method getTypeMappingInfos.

protected TypeMappingInfo[] getTypeMappingInfos() throws Exception {
    if (typeMappingInfos == null) {
        typeMappingInfos = new TypeMappingInfo[1];
        TypeMappingInfo tpi = new TypeMappingInfo();
        tpi.setXmlTagName(new QName("", "testTagname"));
        tpi.setElementScope(ElementScope.Global);
        tpi.setType(String.class);
        typeMappingInfos[0] = tpi;
    }
    return typeMappingInfos;
}
Also used : QName(javax.xml.namespace.QName) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo)

Example 15 with TypeMappingInfo

use of org.eclipse.persistence.jaxb.TypeMappingInfo in project eclipselink by eclipse-ee4j.

the class PrimitiveIntTestCases method getTypeMappingInfos.

protected TypeMappingInfo[] getTypeMappingInfos() throws Exception {
    if (typeMappingInfos == null) {
        typeMappingInfos = new TypeMappingInfo[1];
        TypeMappingInfo tpi = new TypeMappingInfo();
        tpi.setXmlTagName(new QName("", "testTagname"));
        tpi.setElementScope(ElementScope.Global);
        tpi.setNillable(true);
        tpi.setType(int.class);
        typeMappingInfos[0] = tpi;
    }
    return typeMappingInfos;
}
Also used : QName(javax.xml.namespace.QName) TypeMappingInfo(org.eclipse.persistence.jaxb.TypeMappingInfo)

Aggregations

TypeMappingInfo (org.eclipse.persistence.jaxb.TypeMappingInfo)94 QName (javax.xml.namespace.QName)83 Annotation (java.lang.annotation.Annotation)19 Type (java.lang.reflect.Type)18 JAXBContext (org.eclipse.persistence.jaxb.JAXBContext)17 HashMap (java.util.HashMap)6 JAXBContext (jakarta.xml.bind.JAXBContext)5 JAXBElement (jakarta.xml.bind.JAXBElement)4 Map (java.util.Map)4 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)4 Element (org.w3c.dom.Element)4 JAXBException (org.eclipse.persistence.exceptions.JAXBException)3 JAXBMarshaller (org.eclipse.persistence.jaxb.JAXBMarshaller)3 TypeInfo (com.sun.xml.ws.spi.db.TypeInfo)2 XmlElement (jakarta.xml.bind.annotation.XmlElement)2 XmlList (jakarta.xml.bind.annotation.XmlList)2 XmlRootElement (jakarta.xml.bind.annotation.XmlRootElement)2 StringWriter (java.io.StringWriter)2 GenericArrayType (java.lang.reflect.GenericArrayType)2 ArrayList (java.util.ArrayList)2