コード例 #1
0
  public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) {
    super(new LinkedHashMap<String, Object>(), writeDefaults);
    this.format = format;

    DumperOptions options = new FancyDumperOptions();
    options.setIndent(4);
    options.setDefaultFlowStyle(format.getStyle());

    Representer representer = new FancyRepresenter();
    representer.setDefaultFlowStyle(format.getStyle());

    yaml = new Yaml(new SafeConstructor(), representer, options);

    this.file = file;
  }
コード例 #2
0
 public void testDumpClassTag() {
   Car car = new Car();
   car.setPlate("12-XP-F4");
   List<Wheel> wheels = new ArrayList<Wheel>();
   for (int i = 1; i < 6; i++) {
     Wheel wheel = new Wheel();
     wheel.setId(i);
     wheels.add(wheel);
   }
   car.setWheels(wheels);
   Representer representer = new Representer();
   representer.addClassTag(Car.class, new Tag("!car"));
   representer.addClassTag(Wheel.class, Tag.MAP);
   Yaml yaml = new Yaml(representer);
   String output = yaml.dump(car);
   assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), output);
 }