Use JAXB to create Object from XML String

前端 未结 5 814
一向
一向 2020-12-02 04:05

How can I use the below code to unmarshal a XML string an map it to the JAXB object below?

JAXBContext jaxbContext = JAXBContext.newInstance(Person.class);
U         


        
5条回答
  •  爱一瞬间的悲伤
    2020-12-02 04:44

    There is no unmarshal(String) method. You should use a Reader:

    Person person = (Person) unmarshaller.unmarshal(new StringReader("xml string"));
    

    But usually you are getting that string from somewhere, for example a file. If that's the case, better pass the FileReader itself.

提交回复
热议问题