本文整理汇总了Java中org.yaml.snakeyaml.DumperOptions.setAllowReadOnlyProperties方法的典型用法代码示例。如果您正苦于以下问题:Java DumperOptions.setAllowReadOnlyProperties方法的具体用法?Java DumperOptions.setAllowReadOnlyProperties怎么用?Java DumperOptions.setAllowReadOnlyProperties使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.DumperOptions
的用法示例。
在下文中一共展示了DumperOptions.setAllowReadOnlyProperties方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDump
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testDump() {
Blog blog = new Blog("Test Me!");
blog.addPost(new Post("Title1", "text 1"));
blog.addPost(new Post("Title2", "text text 2"));
blog.numbers.add(19);
blog.numbers.add(17);
TreeSet<String> labels = new TreeSet<String>();
labels.add("Java");
labels.add("YAML");
labels.add("SnakeYAML");
blog.setLabels(labels);
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dump(blog);
// System.out.println(output);
assertEquals(Util.getLocalResource("issues/issue73-1.txt"), output);
}
示例2: testBean2
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testBean2() {
IncompleteBean bean = new IncompleteBean();
bean.setName("lunch");
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dumpAsMap(bean);
// System.out.println(output);
assertEquals("id: 10\nname: lunch\n", output);
//
Yaml loader = new Yaml();
try {
loader.loadAs(output, IncompleteBean.class);
fail("Setter is missing.");
} catch (YAMLException e) {
String message = e.getMessage();
assertTrue(
message,
message.contains("Unable to find property 'id' on class: org.yaml.snakeyaml.issues.issue47.IncompleteBean"));
}
}
示例3: toYaml
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
private String toYaml(Object obj) {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setIndent(4);
return new Yaml(options).dump(obj);
}
示例4: testDumpCustomJavaClass
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testDumpCustomJavaClass() {
Hero hero = new Hero("Galain Ysseleg", -3, 2);
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dump(hero);
assertEquals("!!examples.Hero {hp: -3, name: Galain Ysseleg, sp: 2}\n", output);
}
示例5: testRepresenter
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testRepresenter() {
Dice dice = new Dice(3, 6);
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dump(dice);
assertEquals("!!examples.Dice {a: 3, b: 6}\n", output);
}
示例6: testDumpFlow
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testDumpFlow() {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(new SetRepresenter(), options);
String output = yaml.dump(createBlog());
// System.out.println(output);
assertEquals(Util.getLocalResource("issues/issue73-dump7.txt"), output);
//
check(output);
}
示例7: testDumpBlock
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testDumpBlock() {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
options.setDefaultFlowStyle(FlowStyle.BLOCK);
Yaml yaml = new Yaml(new SetRepresenter(), options);
String output = yaml.dump(createBlog());
// System.out.println(output);
assertEquals(Util.getLocalResource("issues/issue73-dump8.txt"), output);
//
check(output);
}
示例8: test2beans
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void test2beans() {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
Person person = new Person("Alan", "Gutierrez", 9);
String etalon = "!!org.yaml.snakeyaml.issues.issue8.Person {firstName: Alan, hatSize: 9, lastName: Gutierrez}\n";
assertEquals(etalon, yaml.dump(person));
Horse horse = new Horse("Tom", person);
String etalon2 = "!!org.yaml.snakeyaml.issues.issue8.PrattleRepresenterTest$Horse\nname: Tom\nowner: {firstName: Alan, hatSize: 9, lastName: Gutierrez}\n";
assertEquals(etalon2, yaml.dump(horse));
}
示例9: testMap
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testMap() throws Exception {
BeanWithMap fact = new BeanWithMap();
GenericMap<Integer> shash = fact.getMap();
shash.put("toto", new Integer(10));
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
// String txt = yaml.dump(fact);
// assertTrue(txt.contains("org.yaml.snakeyaml.issues.issue143.GenericMapTest"));
}
示例10: testRepresenterNoConstructorAvailable
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testRepresenterNoConstructorAvailable() {
MyBean2 bean = new MyBean2("Gnome", true);
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
assertEquals("!!org.yaml.snakeyaml.representer.RepresenterTest$MyBean2 {valid: true}\n",
yaml.dump(bean));
}
示例11: testRepresentor
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testRepresentor() {
IncompleteJavaBean bean = new IncompleteJavaBean();
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dump(bean);
String className = this.getClass().getPackage().getName();
assertEquals("!!" + className + ".IncompleteJavaBean {name: No name}\n", output);
}
示例12: testNoTemplate
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public void testNoTemplate() {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
Yaml yaml = new Yaml(options);
String output = yaml.dumpAsMap(createBean());
// System.out.println(output);
assertEquals(Util.getLocalResource("template/etalon1.yaml"), output);
}
示例13: serializeObject
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
public static String serializeObject(Object obj) {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(false);
options.setIndent(4);
Yaml yaml = new Yaml(new OptimizationRepresenter(), options);
return yaml.dump(obj);
}
示例14: createYaml
import org.yaml.snakeyaml.DumperOptions; //导入方法依赖的package包/类
/**
* Creates and returns a new {@link Yaml} instance for (optional)
* use in writing {@link ConfigOrBuilder} and {@link
* MetadataOrBuilder} objects.
*
* <p>This method never returns {@code null}.</p>
*
* <p>Overrides of this method must not return {@code null}.</p>
*
* <p>Behavior is undefined if overrides of this method interact
* with other methods defined by this class.</p>
*
* @return a non-{@code null} {@link Yaml} instance
*/
protected Yaml createYaml() {
final Representer representer = new TerseRepresenter();
representer.setPropertyUtils(new CustomPropertyUtils());
final DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
return new Yaml(new Constructor(), representer, options);
}