use of org.eclipse.persistence.jaxb.JAXBMarshaller in project metro-jax-ws by eclipse-ee4j.
the class JAXBBond method marshal.
// TODO NamespaceContext nsContext
@Override
public void marshal(T object, OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
JAXBMarshaller marshaller = null;
try {
marshaller = parent.mpool.allocate();
marshaller.setAttachmentMarshaller(am);
marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
if (mappingInfo != null) {
if (isParameterizedType) {
JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
marshaller.marshal(jte, new StreamResult(output), mappingInfo);
} else {
JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
// marshaller.marshal(elt, output);
// GAG missing
marshaller.marshal(elt, new StreamResult(output), mappingInfo);
}
} else {
marshaller.marshal(object, output);
}
} finally {
if (marshaller != null) {
marshaller.setAttachmentMarshaller(null);
parent.mpool.replace(marshaller);
}
}
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project metro-jax-ws by eclipse-ee4j.
the class JAXBBond method marshal.
@Override
public void marshal(T object, Node output) throws JAXBException {
JAXBMarshaller marshaller = null;
try {
marshaller = parent.mpool.allocate();
// marshaller.setAttachmentMarshaller(am);
marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
if (mappingInfo != null) {
if (isParameterizedType) {
JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
marshaller.marshal(jte, new DOMResult(output), mappingInfo);
} else {
JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
// marshaller.marshal(elt, output);
marshaller.marshal(elt, new DOMResult(output), mappingInfo);
}
} else {
marshaller.marshal(object, output);
}
} finally {
if (marshaller != null) {
marshaller.setAttachmentMarshaller(null);
parent.mpool.replace(marshaller);
}
}
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project metro-jax-ws by eclipse-ee4j.
the class JAXBBond method marshal.
@Override
public void marshal(T object, Result result) throws JAXBException {
JAXBMarshaller marshaller = null;
try {
marshaller = parent.mpool.allocate();
marshaller.setAttachmentMarshaller(null);
marshaller.setProperty(jakarta.xml.bind.Marshaller.JAXB_FRAGMENT, true);
if (mappingInfo != null) {
if (isParameterizedType) {
JAXBTypeElement jte = new JAXBTypeElement(mappingInfo.getXmlTagName(), object, (ParameterizedType) mappingInfo.getType());
marshaller.marshal(jte, result, mappingInfo);
} else {
JAXBElement<T> elt = new JAXBElement<>(mappingInfo.getXmlTagName(), (Class<T>) mappingInfo.getType(), object);
// marshaller.marshal(elt, result);
marshaller.marshal(elt, result, mappingInfo);
}
} else {
TypeMappingInfo tmi = null;
if (object instanceof JAXBElement) {
QName q = ((JAXBElement) object).getName();
JAXBContext ctx = (JAXBContext) parent.getJAXBContext();
Map<TypeMappingInfo, QName> mtq = ctx.getTypeMappingInfoToSchemaType();
for (Map.Entry<TypeMappingInfo, QName> es : mtq.entrySet()) {
if (q.equals(es.getValue())) {
tmi = es.getKey();
break;
}
}
}
if (tmi != null) {
marshaller.marshal(object, result, tmi);
} else {
marshaller.marshal(object, result);
}
}
} finally {
if (marshaller != null) {
marshaller.setAttachmentMarshaller(null);
parent.mpool.replace(marshaller);
}
}
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project aai-aai-common by onap.
the class PojoUtils method getJsonFromDynamicObject.
/**
* Gets the json from dynamic object.
*
* @param ent the ent
* @param jaxbContext the jaxb context
* @param includeRoot the include root
* @return the json from dynamic object
* @throws JsonGenerationException the json generation exception
* @throws JsonMappingException the json mapping exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws JAXBException the JAXB exception
*/
public String getJsonFromDynamicObject(DynamicEntity ent, org.eclipse.persistence.jaxb.JAXBContext jaxbContext, boolean includeRoot) throws JsonGenerationException, JsonMappingException, IOException, JAXBException {
JAXBMarshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(JAXBMarshaller.JAXB_FORMATTED_OUTPUT, false);
marshaller.setProperty(MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, Boolean.FALSE);
marshaller.setProperty("eclipselink.json.include-root", includeRoot);
marshaller.setProperty("eclipselink.media-type", "application/json");
StringWriter writer = new StringWriter();
marshaller.marshal(ent, writer);
return writer.toString();
}
use of org.eclipse.persistence.jaxb.JAXBMarshaller in project aai-aai-common by onap.
the class PojoUtilsTest method testGetJsonFromDynamicObject.
@Test
public void testGetJsonFromDynamicObject() throws Exception {
DynamicEntity dynamicEntity = Mockito.mock(DynamicEntity.class);
JAXBContext jaxbContext = Mockito.mock(JAXBContext.class);
JAXBMarshaller marshaller = Mockito.mock(JAXBMarshaller.class);
Mockito.when(jaxbContext.createMarshaller()).thenReturn(marshaller);
String output = pojoUtils.getJsonFromDynamicObject(dynamicEntity, jaxbContext, true);
assertEquals("", output);
}
Aggregations