@Override public T convert(ResponseBody value) throws IOException { try { Unmarshaller unmarshaller = context.createUnmarshaller(); XMLStreamReader streamReader = xmlInputFactory.createXMLStreamReader(value.charStream()); return unmarshaller.unmarshal(streamReader, type).getValue(); } catch (JAXBException | XMLStreamException e) { throw new RuntimeException(e); } finally { value.close(); } } }
protected Object unmarshalStaxSource(Unmarshaller jaxbUnmarshaller, Source staxSource) throws JAXBException { XMLStreamReader streamReader = StaxUtils.getXMLStreamReader(staxSource); if (streamReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(streamReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(streamReader)); } else { XMLEventReader eventReader = StaxUtils.getXMLEventReader(staxSource); if (eventReader != null) { return (this.mappedClass != null ? jaxbUnmarshaller.unmarshal(eventReader, this.mappedClass).getValue() : jaxbUnmarshaller.unmarshal(eventReader)); } else { throw new IllegalArgumentException("StaxSource contains neither XMLStreamReader nor XMLEventReader"); } } }
public void serializeBody(JAXBElement e, XMLSerializer target, Object outerPeer) throws SAXException, IOException, XMLStreamException { Class scope = e.getScope(); if(e.isGlobalScope()) scope = null; QName n = e.getName(); ElementBeanInfoImpl bi = grammar.getElement(scope,n); if(bi==null) { tbi = grammar.getBeanInfo(e.getDeclaredType(),true); } catch (JAXBException x) { return; Object value = e.getValue(); target.startElement(n.getNamespaceURI(),n.getLocalPart(),n.getPrefix(),null); if(value==null) {
Object wrapped = ((JAXBElement)value).getValue(); QName qname = ((JAXBElement)value).getName(); clazz, wrapped); JAXBSource source = new JAXBSource(jc, contentObject); elem = jc.createUnmarshaller().unmarshal(source, clazz); JAXBElement<T> contentObject = new JAXBElement<T>(new QName(clazz.getSimpleName()), clazz, value); JAXBSource source = new JAXBSource(jc, contentObject); elem = jc.createUnmarshaller().unmarshal(source, clazz); } else { @SuppressWarnings("unchecked") T resT = (T) elem.getValue(); res = resT;
Object jaxb = null; try { Unmarshaller u = Context.jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); jaxb = u.unmarshal(n); } catch (JAXBException e1) { if (jb.getDeclaredType() .getName() .equals("org.docx4j.dml.wordprocessingDrawing.Inline")) { this.inline = (Inline) jb.getValue(); } else if (jb .getDeclaredType() .getName() .equals("org.docx4j.dml.wordprocessingDrawing.Anchor")) { this.anchor = (Anchor) jb.getValue(); } else { log.error("UNEXPECTED "
/** * If an object is wrapped in a JAXBElement, return the object. * Warning: be careful with this. If you are copying objects * into your document (rather than just reading them), you'll * probably want the object to remain wrapped (JAXB usually wraps them * for a reason; without the wrapper, you'll (probably?) need an * @XmlRootElement annotation in order to be able to marshall ie save your * document). * * @param o * @return */ public static Object unwrap(Object o) { if (o==null) return null; if (o instanceof javax.xml.bind.JAXBElement) { log.debug("Unwrapped " + ((JAXBElement)o).getDeclaredType().getName() ); log.debug("name: " + ((JAXBElement)o).getName() ); return ((JAXBElement)o).getValue(); } else { return o; } /* * Interestingly, DocumentSettingsPart (settings.xml) gets unwrapped, * and CTSettings does not have @XmlRootElement, but this does * not cause a problem when it is marshalled. */ }
private Authorizations unmarshallAuthorizations() throws JAXBException { try { final XMLStreamReader xsr = XmlUtils.createSafeReader(new StreamSource(authorizationsFile)); final Unmarshaller unmarshaller = JAXB_AUTHORIZATIONS_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(authorizationsSchema); final JAXBElement<Authorizations> element = unmarshaller.unmarshal(xsr, Authorizations.class); return element.getValue(); } catch (XMLStreamException e) { logger.error("Encountered an error reading authorizations file: ", e); throw new JAXBException("Error reading authorizations file", e); } }
public void serializeBody(JAXBElement e, XMLSerializer target, Object outerPeer) throws SAXException, IOException, XMLStreamException { Class scope = e.getScope(); if(e.isGlobalScope()) scope = null; QName n = e.getName(); ElementBeanInfoImpl bi = grammar.getElement(scope,n); if(bi==null) { tbi = grammar.getBeanInfo(e.getDeclaredType(),true); } catch (JAXBException x) { return; Object value = e.getValue(); target.startElement(n.getNamespaceURI(),n.getLocalPart(),n.getPrefix(),null); if(value==null) {
Unmarshaller unmarshaller = ctx.createUnmarshaller(); unmarshaller = new SecureUnmarshaller(unmarshaller, disableExternalEntities, enableSecureProcessingFeature, disableDTDs); ele = unmarshaller.unmarshal(source, JaxbMap.class); ele = ctx.createUnmarshaller().unmarshal(source, JaxbMap.class); if (!wrapped.map().equals(ele.getName().getLocalPart())) throw new JAXBUnmarshalException(Messages.MESSAGES.mapWrappingFailedLocalPart(wrapped.map(), ele.getName().getLocalPart())); if (!wrapped.namespace().equals(ele.getName().getNamespaceURI())) throw new JAXBUnmarshalException(Messages.MESSAGES.mapWrappingFailedNamespace(wrapped.namespace(), ele.getName().getNamespaceURI())); jaxbMap = ele.getValue(); Unmarshaller unmarshaller = ctx.createUnmarshaller(); unmarshaller = AbstractJAXBProvider.decorateUnmarshaller(valueType, annotations, mediaType, unmarshaller); Object value = unmarshaller.unmarshal(element.getFirstChild()); if (xmlAdapter != null)
private String getInstrText(R run) { List<Object> rContent = run.getContent(); Object item = null; Text text = null; for (int i=0; i<rContent.size(); i++) { item = rContent.get(i); if (item instanceof JAXBElement && ((JAXBElement)item).getName().equals(_RInstrText_QNAME)) { text = (Text)((JAXBElement)item).getValue(); break; } } return (text != null ? text.getValue() : null); }
public HTTP(final HTTP that){ if (that != null && that.getOrPost != null) { this.getOrPost = new ArrayList<>(); for (JAXBElement<RequestMethodType> j : that.getOrPost) { this.getOrPost.add(new JAXBElement<>(j.getName(), j.getDeclaredType(), new RequestMethodType(j.getValue()))); } } }
public static Object unmarshalString(String str, JAXBContext jc, Class declaredType) throws JAXBException { Unmarshaller u = jc.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); Object o = u.unmarshal( new javax.xml.transform.stream.StreamSource(new java.io.StringReader(str)), declaredType); if (o instanceof JAXBElement) { return ((JAXBElement)o).getValue(); } else { return o; } }
@Override protected Object readFrom(Class<Object> type, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws JAXBException { final SAXSource s = getSAXSource(spf.get(), entityStream); if (type.isAnnotationPresent(XmlRootElement.class)) { return u.unmarshal(s); } else { return u.unmarshal(s, type).getValue(); } } }
@SuppressWarnings({ "unchecked", "rawtypes" }) private JAXBElement<?> doDuplicateJAXBElement(JAXBElement<?> originalObject) { if (originalObject == null) return null; final JAXBElement<?> sourceElement = (JAXBElement<?>) originalObject; final Object sourceObject = sourceElement.getValue(); final Object copyObject = doDuplicate(sourceObject); final JAXBElement copyElement = new JAXBElement( sourceElement.getName(), sourceElement.getDeclaredType(), sourceElement.getScope(), copyObject); return copyElement; }
Unmarshaller unmarshaller = ctx.createUnmarshaller(); unmarshaller = new SecureUnmarshaller(unmarshaller, disableExternalEntities, enableSecureProcessingFeature, disableDTDs); ele = unmarshaller.unmarshal(source, JaxbCollection.class); ele = ctx.createUnmarshaller().unmarshal(source, JaxbCollection.class); if (wrapped != null) if (!wrapped.element().equals(ele.getName().getLocalPart())) throw new JAXBUnmarshalException(Messages.MESSAGES.collectionWrappingFailedLocalPart(wrapped.element(), ele.getName().getLocalPart())); if (!wrapped.namespace().equals(ele.getName().getNamespaceURI())) throw new JAXBUnmarshalException(Messages.MESSAGES.collectionWrappingFailedNamespace(wrapped.namespace(), ele.getName().getNamespaceURI())); col = ele.getValue(); Unmarshaller unmarshaller = ctx.createUnmarshaller(); unmarshaller = AbstractJAXBProvider.decorateUnmarshaller(baseType, annotations, mediaType, unmarshaller); if (type.isArray()) Object o = unmarshaller.unmarshal(val); if (xmlAdapter != null)