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());
}
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()));
}
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;
}
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;
}
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;
}
Aggregations