当我尝试从数据文件创建对象时,当assest
类存在时出现以下异常。我试过用 dum;它能够转储数据,但是当我尝试读取相同的数据时,出现以下异常:
[ConstructorException: null; Can't construct a java object for tag:yaml.org,2002:model.Asset; exception=Class not found: model.Asset]
文件阅读器:
package utill;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.*;
import java.io.InputStream;
import java.util.*;
import model.*;
import java.util.LinkedHashMap;
import org.yaml.snakeyaml.constructor.Constructor;
public class FileReaderUtill {
public static List getAssest(String fileName){
LinkedHashMap<String,Asset> assest=null;
List<Asset> data= new ArrayList<Asset>();
try{
InputStream input = new FileInputStream(new
File("conf/datafile.yaml"));
Yaml yaml = new Yaml();
data=(List<Asset>)yaml.load(input);
//System.out.println(assest.get("Asset0"));
}catch(IOException e){
e.printStackTrace();
}
return data;
}
}
数据文件.yaml
- !!model.Asset {cid: null, enable: '1', id: re, internalName: df, name: fd}
- !!model.Asset {cid: null, enable: '0', id: rexz, internalName: dxxf, name: fdxxx}
评估.java
package model;
public class Asset {
public Asset(){
}
public Asset(String id,String cid,String name,String internalName,String enable ){
this.id=id;
this.name=name;
this.internalName=internalName;
this.enable=enable;
}
public String id;
public String cid;
public String name;
public String internalName;
public String enable;
}
请帮我解决这个问题。