使用Jackson不对称的Yaml编码/解码

时间:2018-07-18 10:33:31

标签: java jackson yaml jackson-databind snakeyaml

当我执行以下命令时:

ObjectMapper mapper = new ObjectMapper( new YAMLFactory() );
try {

  Map matchReport = mapper
      .readValue( new File( "C:\\temp\\test.yaml" ),Map.class );

  mapper.writeValue( System.out, matchReport );
}
catch ( Exception e ) {
  e.printStackTrace();
}
}

对于以下输入:

{
  "$id": "1",
  "$type": "LongoMatch.Core.Store.Project, LongoMatch.Core",
  "ID": "ae8a4461-b385-4b80-9a54-2254147820f8",
  "Periods": [
    {
      "$id": "106",
      "$type": "LongoMatch.Core.Store.Period, LongoMatch.Core",
      "ID": "4e1d0f3f-6dfb-40b0-b7f9-3743c661510d",
      "Name": "1",
      "Nodes": [
        {
          "$id": "107",
          "$type": "LongoMatch.Core.Store.TimeNode, LongoMatch.Core",
          "Name": "1",
          "Start": 0,
          "Stop": 1275931,
          "EventTime": 0,
          "Rate": 1.0
        }
      ],
      "Team": 0
    },
    {
      "$id": "108",
      "$type": "LongoMatch.Core.Store.Period, LongoMatch.Core",
      "ID": "79d8422e-0ff0-44bf-836d-cb2f4d41ea53",
      "Name": "2",
      "Nodes": [
        {
          "$id": "109",
          "$type": "LongoMatch.Core.Store.TimeNode, LongoMatch.Core",
          "Name": "2",
          "Start": 1275931,
          "Stop": 2551862,
          "EventTime": 1275931,
          "Rate": 1.0
        }
      ],
      "Team": 0
    }
  ],
  "Timers": [],
  "Playlists": []
}

我得到以下输出:

$id: "1"
$type: "LongoMatch.Core.Store.Project, LongoMatch.Core"
ID: "ae8a4461-b385-4b80-9a54-2254147820f8"
Periods:
- $id: "106"
  $type: "LongoMatch.Core.Store.Period, LongoMatch.Core"
  ID: "4e1d0f3f-6dfb-40b0-b7f9-3743c661510d"
  Name: "1"
  Nodes:
  - $id: "107"
    $type: "LongoMatch.Core.Store.TimeNode, LongoMatch.Core"
    Name: "1"
    Start: 0
    Stop: 1275931
    EventTime: 0
    Rate: 1.0
  Team: 0
- $id: "108"
  $type: "LongoMatch.Core.Store.Period, LongoMatch.Core"
  ID: "79d8422e-0ff0-44bf-836d-cb2f4d41ea53"
  Name: "2"
  Nodes:
  - $id: "109"
    $type: "LongoMatch.Core.Store.TimeNode, LongoMatch.Core"
    Name: "2"
    Start: 1275931
    Stop: 2551862
    EventTime: 1275931
    Rate: 1.0
  Team: 0
Timers: []
Playlists: []

是否存在并且可以强制写入[]和{}而不是-的选项? 我尝试了CANONICAL_OUTPUT选项。但是随后我得到了[]和{}以及许多其他字符。 编码回流后,是否存在和选项可以获得完全相同的结果?

0 个答案:

没有答案