I do not have much experience with Serialization. While trying to serialize a simple object of the class below i get this No JavaBean properties found exception
from YAML library.
Here is the class:
public class MyClass {
String value;
public MyClass(String args) {
value = args;
}
public String getValue(){
return value;
}
}
And here is how i am serializing using SnakeYAMAL:
import java.util.HashMap;
import java.util.Map;
import org.yaml.snakeyaml.Yaml;
public class Test {
public static void main(String[] args) {
MyClass obj = new MyClass("this is my data");
Map<String, Object> data = new HashMap<String, Object>();
data.put("MyClass", obj);
Yaml yaml = new Yaml();
String output = yaml.dump(data);
System.out.println(output);
}
}
and upon executing, this exception is thrown:
Exception in thread "main" org.yaml.snakeyaml.error.YAMLException: No JavaBean properties found in MyClass
at org.yaml.snakeyaml.introspector.PropertyUtils.getProperties(PropertyUtils.java:112) ...
Can you tell me what is it that i am missing in doing this, or how should i do it properly?
EDIT:
public class MyClass {
String value;
public MyClass() {}
public String setValue(String value){
this.value = value;
}
public String getValue(){
return value;
}
}
and if i set the value before serializing it, it somehow works. Do you think it is proper solution or not a recommended approach?