当我尝试在数据文件中创建对象时,在获取以下异常时会出现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;
}
}
Datafile.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}
Assest.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;
}
请帮我解决这个问题。