如何不反序列化特定字段

问题描述

我正在为一个名为Appstream的规范进行包装,该规范由一个XML文件组成,该XML文件描述了到软件中心的软件包。

我一直在努力处理这种情况,sepc允许您设置类似于以下内容的描述标签

    <description>
        <p>
      Power Statistics is a program used to view historical and current battery
      @R_837_4045@ion and will show programs running on your computer using power.
        </p>
        <p>Example list:</p>
        <ul>
            <li>First item</li>
            <li>Second item</li>
        </ul>
        <p>
      You probably only need to install this application if you are having problems
      with your laptop battery,or are trying to work out what programs are using
      significant amounts of power.
        </p>
    </description>

quick-xml(基于Serde的XML库)允许您使用rename="$value"获取标记的内部值。问题是我想以某种方式在Serde尝试序列化之前获取原始字符串,否则我将只获得Seq标签。这样的事情有可能吗?

解决方法

听起来您可能想覆盖该字段的序列化实现。 Serde允许使用max-attempts: 6属性:docs

Custom Date Format中的serialize_with函数显示了如何为属性实现自定义序列化的示例。 (示例中使用的with属性是Serializeserialize_with的简写。)