<dependency> <groupId>io.protostuff</groupId> <artifactId>protostuff-core</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>io.protostuff</groupId> <artifactId>protostuff-yaml</artifactId> <version>1.6.1</version> </dependency> public class Person { private String name; private int age; @Override public String toString() { return "Person [name=" + name + ", age=" + age + "]"; } } RuntimeSchema<Person> schema = RuntimeSchema.createFrom(Person.class); String yaml = YamlIOUtil.writeTo(person, schema, LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE)).toString(); System.out.println(yaml); yaml --- !!io.protostuff.Person age: 25 public class Person { private String name; private int age; } RuntimeSchema<Person> schema = RuntimeSchema.createFrom(Person.class); Person person = new Person(); YamlIOUtil.mergeFrom(yaml, person, schema); System.out.println(person);


上一篇:
下一篇:
切换中文