オブジェクトを表現に変換するために使用する次のメソッドがありますyaml
(たとえば、コンソールに出力できます)
@Nonnull
private String outputObject(@Nonnull final ObjectToPrint packageSchedule) {
DumperOptions options = new DumperOptions();
options.setAllowReadOnlyProperties(true);
options.setPrettyFlow(true);
return new Yaml(new Constructor(), new JodaTimeRepresenter(), options).dump(ObjectToPrint);
}
すべてObjectToPrint
問題ありませんが、構造内に含まれる一部のオブジェクトについては、実際のオブジェクトの内容ではなく、参照名のようなものを取得します。
!!com.blah.blah.ObjectToPrint
businessYears:
- businessYearMonths: 12
ppiYear: &id001 {
endDate: 30-06-2013,
endYear: 2013,
startDate: 01-07-2012,
startYear: 2012
}
ppiPeriod:
ppiYear: *id001
endDate: 27-03-2014
startDate: 21-06-2013
units: 24.000
number: 1
上記の例からわかるように、ppiYear
オブジェクトが印刷され ( としてマークされています$id001
)、同じオブジェクトが使用されてppiPeriod
いますが、オブジェクトの内容ではなく参照名のみが印刷されています。yaml に変換したい構造内でそのオブジェクトを使用するたびに、オブジェクトの内容を出力する方法 ( ObjectToPrint
)。PS。参照名をまったく出力しないのはいいことですが ( &id001
)、それは重要ではありません