DataStreamファイルを非整列化するためにXStreamを使用します。 私はmain()関数を使って実行すると完全に動作しますが、私が起動したときに起動すると、UnknownFieldExceptionが返されます。UnknownFieldExceptionは、春起動アプリケーションでのみ
によって引き起こさ:com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter $ UnknownFieldException:いいえ、そのようなフィールドworkshop.tokenizer.data.Attributes.attributeは ----デバッグ情報---- メッセージ:いいえそのようなフィールドworkshop.tokenizer.data.Attributes.attribute フィールド:属性 クラス:workshop.tokenizer.data.Attributes required-type:workshop.tokenizer.data.Attributes converter-type:com.thoughtworks.xstream.converters。 reflection.ReflectionConverter クラス[1]:workshop.tokenizer.data.DataObj クラス[2]:java.util.ArrayList コンバータ型[1]:com.thoughtworks.xstream.converters.collections.CollectionConverter クラス[3]:workshop.tokenizer.wrappers.DataObjects バージョン:1.4.9
私はこれを呼んでいますメインオブジェクトを作成する方法は、この例外で失敗し、私はから同じライン「メインパブリック静的ボイド...」と呼ぶかどうかは完全にメイン内部
@RequestMapping(method = RequestMethod.POST, value = "/test")
public ResponseEntity<SFRecord> execute(@RequestBody RequestDto json)
throws ClassNotFoundException, SQLException, FileNotFoundException {
Request request = json.convert();
Main main = new Main();
RequestObj reqObj = main.execute(request.getSentence());
ResponseEntity<SFRecord> result = restTemplate.exchange(parserUrl, HttpMethod.POST,
new HttpEntity<RequestObj>(reqObj), SFRecord.class);
return result;
}
を作品data.xmlに
を非整列化するために、このラインを使用していますFileReader reader = new FileReader("Files/Data.xml");
objects = (DataObjects) xstream.fromXML(reader);
なぜ奇妙な行動か?
おかげ
更新
私はXStreamAlias注釈が無視されていることに気づいたので、私は xstream.autodetectAnnotations(真)を添加し; しかし、今、私はこの例外を取得:
java.lang.ClassCastException: wrappers.DataObjects cannot be cast to wrappers.DataObjects
私は、XMLを非整列化するために、このラインを使用しています:
FileReader reader = new FileReader("Files/Data.xml");
DataObjects objects = (DataObjects) xstream.fromXML(reader);