• <small id='i2hQF'></small><noframes id='i2hQF'>

          <bdo id='i2hQF'></bdo><ul id='i2hQF'></ul>
        <tfoot id='i2hQF'></tfoot>
      1. <legend id='i2hQF'><style id='i2hQF'><dir id='i2hQF'><q id='i2hQF'></q></dir></style></legend>

        <i id='i2hQF'><tr id='i2hQF'><dt id='i2hQF'><q id='i2hQF'><span id='i2hQF'><b id='i2hQF'><form id='i2hQF'><ins id='i2hQF'></ins><ul id='i2hQF'></ul><sub id='i2hQF'></sub></form><legend id='i2hQF'></legend><bdo id='i2hQF'><pre id='i2hQF'><center id='i2hQF'></center></pre></bdo></b><th id='i2hQF'></th></span></q></dt></tr></i><div id='i2hQF'><tfoot id='i2hQF'></tfoot><dl id='i2hQF'><fieldset id='i2hQF'></fieldset></dl></div>

        Jackson Yaml 类型信息在序列化时出错

        时间:2023-09-26
        <tfoot id='d9LHs'></tfoot>

          <small id='d9LHs'></small><noframes id='d9LHs'>

              <tbody id='d9LHs'></tbody>
            <i id='d9LHs'><tr id='d9LHs'><dt id='d9LHs'><q id='d9LHs'><span id='d9LHs'><b id='d9LHs'><form id='d9LHs'><ins id='d9LHs'></ins><ul id='d9LHs'></ul><sub id='d9LHs'></sub></form><legend id='d9LHs'></legend><bdo id='d9LHs'><pre id='d9LHs'><center id='d9LHs'></center></pre></bdo></b><th id='d9LHs'></th></span></q></dt></tr></i><div id='d9LHs'><tfoot id='d9LHs'></tfoot><dl id='d9LHs'><fieldset id='d9LHs'></fieldset></dl></div>
            • <bdo id='d9LHs'></bdo><ul id='d9LHs'></ul>

                  <legend id='d9LHs'><style id='d9LHs'><dir id='d9LHs'><q id='d9LHs'></q></dir></style></legend>

                  本文介绍了Jackson Yaml 类型信息在序列化时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  通过 Jackson 将对象序列化为 yml 时,我得到以下输出:

                  I am getting the following output when serializing an object to yml via Jackson:

                  ---
                  commands:
                    dev: !<foo.bar.baz.DevCommand>
                  

                  但是,我想要的是:

                  ---
                  commands:
                    dev: 
                      type: foo.bar.baz.DevCommand
                  

                  我能够很好地反序列化.也就是说,反序列化部分按预期工作.我在我能想到的任何地方都放了以下注释:

                  I am able to deserialize that fine. That is to say, the deserialization part works as intended. I have put the following annotation everywhere I can think of:

                  @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="type")
                  

                  包括 DevCommand 接口、DevCommand 上的具体类、具有 commands 映射的类型(字段和 getter/setter).

                  Including on the DevCommand interface, on DevCommand the concrete class, on the type which has the commands map (both the field and the getters/setters).

                  我需要做什么来强制 Jackson 使用我想要的类型格式?

                  What do I need to do to force Jackson to use the type format I want?

                  推荐答案

                  Yaml 已经内置了类型信息,所以 Jackson 默认使用它.从 this issue,修复是禁用使用本机类型 ID.

                  Yaml has type information built in already, so Jackson uses that by default. From this issue, the fix is to disable using the native type id.

                  YAML 具有原生类型 ID 和对象 ID,因此默认使用它们(假设这是用户喜欢的).但是您可以通过以下方式禁用它:

                  YAML has native Type Ids and Object Ids, so by default those are used (assuming this is what users prefer). But you can disable this with:

                  YAMLGenerator.Feature.USE_NATIVE_TYPE_ID
                  

                  并专门禁用它;类似:

                  YAMLFactory f = new YAMLFactory();
                  f.disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
                  ObjectMapper m = new ObjectMapper(f);
                  

                  或者,为了方便

                  YAMLMapper m = new YAMLMapper()
                   disable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
                  

                  这篇关于Jackson Yaml 类型信息在序列化时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java 类在 Jar 中读取 Yaml 下一篇:如何在 Java 中优雅地序列化和反序列化 OpenCV YA

                  相关文章

                  最新文章

                    <bdo id='j3wTZ'></bdo><ul id='j3wTZ'></ul>

                  1. <small id='j3wTZ'></small><noframes id='j3wTZ'>

                  2. <i id='j3wTZ'><tr id='j3wTZ'><dt id='j3wTZ'><q id='j3wTZ'><span id='j3wTZ'><b id='j3wTZ'><form id='j3wTZ'><ins id='j3wTZ'></ins><ul id='j3wTZ'></ul><sub id='j3wTZ'></sub></form><legend id='j3wTZ'></legend><bdo id='j3wTZ'><pre id='j3wTZ'><center id='j3wTZ'></center></pre></bdo></b><th id='j3wTZ'></th></span></q></dt></tr></i><div id='j3wTZ'><tfoot id='j3wTZ'></tfoot><dl id='j3wTZ'><fieldset id='j3wTZ'></fieldset></dl></div>
                    <tfoot id='j3wTZ'></tfoot>
                    <legend id='j3wTZ'><style id='j3wTZ'><dir id='j3wTZ'><q id='j3wTZ'></q></dir></style></legend>