Jaxb - Unmarshalling
Posted huey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jaxb - Unmarshalling相关的知识,希望对你有一定的参考价值。
A simple approach for unmarshalling an XML document consists of the creation of a JAXB context and the call to unmarshal the document. A JAXBContext
object provides the entry point to the JAXB API and maintains the binding information between XML and Java. One way of creating a context instance is by calling the static method newInstance
with a list of colon separated names of the packages containing the JAXB schema-derived classes. From this context, an Unmarshaller
object is obtained, which functions as the driver for processing an XML text to create the equivalent set of Java objects. It offers several unmarshal
methods, accepting a wide range of object types as the source for XML text data. The method shown below illustrates this with a single package containing the class of the type defining the top level element of the XML document.
public <T> T unmarshal( Class<T> docClass, InputStream inputStream ) throws JAXBException { String packageName = docClass.getPackage().getName(); JAXBContext jc = JAXBContext.newInstance( packageName ); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<T> doc = (JAXBElement<T>)u.unmarshal( inputStream ); return doc.getValue(); }
The return value of the call to JAXB‘s unmarshal
is a representation of the root node of the parsed XML document in an instance of JAXBElement<T>
. If we‘re not interested in the tag of the root element we might just as well return the extracted content value.
以上是关于Jaxb - Unmarshalling的主要内容,如果未能解决你的问题,请参考以下文章
Android Parcelable反序列化报错笔记:java.lang.RuntimeException: Unmarshalling unknown type code at offset(代码片
Akka(34): Http:Unmarshalling,from Json
akka-http 错误:找不到参数 um 的隐式值:akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller
CS: Marshalling and Unmarshalling, Serialization and Unserialization