Error unmarshalling xml in java-8 “secure-processing org.xml.sax.SAXNotRecognizedException causing java.lang.IllegalStateException”

后端 未结 11 502
时光取名叫无心
时光取名叫无心 2020-12-05 00:21

The following code worked fine in Java 7

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

String          


        
11条回答
  •  难免孤独
    2020-12-05 01:09

    Try to create a XML Document and unmarshal it. It was worked for me. JAXBContext jc = JAXBContext.newInstance( Message.class );

            InputStream stream = new ByteArrayInputStream( string.getBytes( StandardCharsets.UTF_8 ) );
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.parse( stream );
    
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            Message msg = ( Message ) unmarshaller.unmarshal( doc );
    

提交回复
热议问题