论坛首页 入门讨论版 Java

JYaml 如何处理set 等类型的?

浏览 124 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
时间:2008-03-17 关键字: yaml
想用YAML保存配置
class Node {
	private String nodeId; //知识点id
	private int count; //题目数量
	private int type; //题目类型
	/**
	 * @return 返回 nodeId。
	 */
	public String getNodeId() {
		return nodeId;
	}
	/**
	 * @param nodeId 要设置的 nodeId。
	 */
	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}
	/**
	 * @return 返回 count。
	 */
	public int getCount() {
		return count;
	}
	/**
	 * @param count 要设置的 count。
	 */
	public void setCount(int count) {
		this.count = count;
	}
	/**
	 * @return 返回 type。
	 */
	public int getType() {
		return type;
	}
	/**
	 * @param type 要设置的 type。
	 */
	public void setType(int type) {
		this.type = type;
	}
}

public class SelectedNodes {
	
	private String subjectTitle;
//	private Set<Node> nodes;
	
	private Node[] nodes;
	/**
	 * @return 返回 nodes。
	 */
	public Node[] getNodes() {
		return nodes;
	}

	/**
	 * @param nodes 要设置的 nodes。
	 */
	public void setNodes(Node[] nodes) {
		this.nodes = nodes;
	}

	/**
	 * @return 返回 subjectTitle。
	 */
	public String getSubjectTitle() {
		return subjectTitle;
	}

	/**
	 * @param subjectTitle 要设置的 subjectTitle。
	 */
	public void setSubjectTitle(String subjectTitle) {
		this.subjectTitle = subjectTitle;
	}

调用
	SelectedNodes selectedNode = new SelectedNodes();
		selectedNode.setSubjectTitle("交际用语,过10题,每题目10分");
		
		Node node = new Node();
		node.setCount(10);
		node.setNodeId("ff80808116c867100116c880ebeb0055");
		node.setType(0);
//		
		Node[] nodes = {node};
		
		selectedNode.setNodes(nodes);
 File dumpfile = new File("d:\\nodes.yaml");
				Yaml.dump(selectedNode, dumpfile);


异常
Exception in thread "main" org.ho.yaml.exception.
ObjectCreationException: Error near line 0: 
Can't create object of
 type class com.bupticet.local.study.util.Node using default constructor.

如何处理?没找到JYAML操作Set等的例子
   
论坛首页 入门讨论版 Java

跳转论坛:
JavaEye推荐