[Simple-support] Custom HashMap serialization/deserialization - Help
Brought to you by:
niallg
|
From: Miguel Á. M. F. <mig...@gm...> - 2012-05-27 23:34:52
|
Hi,
I am trying to serialize (and deserialize) two Java clases (Courses.java
and Couse.Java) in order to get the following XML:
<Courses>
<Course id="course01" name="Carnet de conducir A"/>
<Course id="course02" name="Carnet de conducir A"/>
</Courses>
Course.java:
package com.simpleserializer.model;
import org.simpleframework.xml.Attribute;
public class Course {
@Attribute private String id;
@Attribute private String name;
public Course(String id, String name) {
this.setId(id);
this.setName(name);
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
Course2.java:
package com.simpleserializer.model;
import java.util.HashMap;
public class Courses {
private HashMap<String, Course> courses = new HashMap<String, Course>();
public void put(String courseId, Course course)
{
this.courses.put(courseId, course);
}
}
And example about how these clases are used is:
Courses courses = new Courses();
Course course1 = new Course("course01", "My first course");
Course course2 = new Course("course02", "My second course");
courses.put(course1.getId(), course1);
courses.put(course2.getId(), course2);
Could you please help me? I would really appreciate it!
Thanks!
|