com.e1.ewx.base.model.weixinapi.Event
延伸com.e1.ewx.base.model.weixinapi.BaseMsg
JAXBContext context = JAXBContext.newInstance(Event.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Event eee = (Event)unmarshaller.unmarshal(new StringReader(xmlStr));
System.out.println(eee.getMsgType());
例外:
Exception in thread "main" java.lang.ClassCastException: com.e1.ewx.base.model.weixinapi.BaseMsg cannot be cast to com.e1.ewx.base.model.weixinapi.Event
at Test.main(Test.java:49)
为什么呢?
答案 0 :(得分:0)
似乎xmlStr是BaseMsg实例的表示,而不是Event实例。