<bdo id='XBshr'></bdo><ul id='XBshr'></ul>
<legend id='XBshr'><style id='XBshr'><dir id='XBshr'><q id='XBshr'></q></dir></style></legend>

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

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

  • <tfoot id='XBshr'></tfoot>
      1. Jackson YAML:使用标志映射正则表达式模式

        时间:2023-09-26
        <legend id='eknzh'><style id='eknzh'><dir id='eknzh'><q id='eknzh'></q></dir></style></legend><tfoot id='eknzh'></tfoot>
          <tbody id='eknzh'></tbody>

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

              • <bdo id='eknzh'></bdo><ul id='eknzh'></ul>

                • 本文介绍了Jackson YAML:使用标志映射正则表达式模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Jackson 中,我可以映射 YAML 中的字符串:

                  In Jackson, I can map a string in YAML:

                  regexField: "(\d{2}):(\d{2})"
                  

                  到类上的 Pattern 字段:

                  final class MappedFromYaml {
                      private Pattern regexField;
                      // ... accessors
                  }
                  

                  Jackson 的 ObjectMapper 将创建一个带有默认标志的 Pattern.是否可以使用设置的特定标志来创建它,例如 Pattern.MULTILINE?理想情况下,我希望能够在 YAML 中指定这些标志,但如果未能在 Java 代码中为特定字段指定标志的解决方案也将不胜感激.

                  Jackson's ObjectMapper will create a Pattern with default flags. Is it possible to make it create it with specific flags set, such as Pattern.MULTILINE? Ideally I would like to be able to specify those flags in YAML, but failing that a solution that specifies the flags for a specific field in Java code would also be appreciated.

                  推荐答案

                  有两种方法.第一个是将标志直接嵌入 到正则表达式中:

                  There are two ways. The first is embedding flags directly into the regex:

                  regexField: "(\d{2}):(\d{2})(?m)"
                  

                  否则不要直接映射到Pattern,而是引入一个自定义类型,比如PatternBuilder

                  Otherwise don't map directly to Pattern, but introduce a custom type like a PatternBuilder

                  public class PatternBuilder {
                    public String regex;
                    public boolean multiline;
                    public Pattern pattern() {
                      int flags = 0;
                      if (multiline) flags |= Pattern.MULTILINE;
                      return Pattern.compile(regex, flags);
                    }
                  }
                  

                  可以从 YAML 构建

                  that can be built from the YAML

                  pattern:
                    regex: "(\d{2}):(\d{2})"
                    multiline: true
                  

                  这篇关于Jackson YAML:使用标志映射正则表达式模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 Java 中优雅地序列化和反序列化 OpenCV YA 下一篇:Snakeyaml 似乎不必要地将简单值包装在列表中

                  相关文章

                  最新文章

                  1. <tfoot id='6W1Ff'></tfoot>

                  2. <legend id='6W1Ff'><style id='6W1Ff'><dir id='6W1Ff'><q id='6W1Ff'></q></dir></style></legend>
                    1. <small id='6W1Ff'></small><noframes id='6W1Ff'>

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