You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
other libraries that support yaml are extremely bad at the things you guys are
good at.
for example, you guys are very good at handling injecting data into classes
with custom constructors, coercing generic types, intuitive serializers,
deserializers.
I'm not necessarily asking for advanced yaml, with munging, etc. mainly a
gson-like deserializer for yaml which is as clean as you current code is, and
clearly benefits from all the core stuff in gson that isn't json dependent.
Here's an example of what we otherwise have to deal with:
class SelectiveConstructor extends Constructor {
public SelectiveConstructor() {
// define a custom way to create a mapping node
yamlClassConstructors.put(NodeId.mapping, new MyPersistentObjectConstruct());
}
class MyPersistentObjectConstruct extends Constructor.ConstructMapping {
@Override
protected Object constructJavaBean2ndStep(MappingNode node, Object object) {
Class type = node.getType();
if (type.equals(MyPersistentObject.class)) {
// create a map
Map map = constructMapping(node);
String id = (String) map.get("id");
return new MyPersistentObject(id, 17);
} else {
// create JavaBean
return super.constructJavaBean2ndStep(node, object);
}
}
}
}
public void testConstructor() throws IOException {
Yaml yaml = new Yaml(new SelectiveConstructor());
List<?> data = (List<?>) yaml.load("- 1\n- 2\n- !!examples.MyPersistentObject {amount: 222, id: persistent}");
// System.out.println(data);
assertEquals(3, data.size());
MyPersistentObject myObject = (MyPersistentObject) data.get(2);
assertEquals(17, myObject.getAmount());
assertEquals("persistent", myObject.getId());
}
Original issue reported on code.google.com by [email protected] on 15 May 2011 at 4:08
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
[email protected]
on 15 May 2011 at 4:08The text was updated successfully, but these errors were encountered: