有没有办法防止杰克逊的反序列化现场? [英] Is there any way to prevent field from deserialization in jackson?

查看:135
本文介绍了有没有办法防止杰克逊的反序列化现场?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法阻止杰克逊的字段反序列化?
但我需要序列化该字段
我尝试使用@jsonIgnoreProperties这可以防止序列化和反序列化。

Is there any way to prevent a field from deserialization in jackson? but i need to serialize that field I tried with @jsonIgnoreProperties this prevent both serialization and deserialization.

推荐答案

技巧是将@JsonProperty和@JsonIgnore组合在setter和getter上,如下例所示

The "trick" is to combine the @JsonProperty and @JsonIgnore on the setters and getters, like in the following example

 public class SerializeDemo{

      @JsonIgnore
      private String serializeOnly;


      @JsonProperty("serializeOnly")
      public String getSerializeOnly() {
        return serializeOnly;
      }

      @JsonIgnore
      public void setSerializeOnly(String serializeOnly) {
        this.serializeOnly= serializeOnly;
      }
    }

这篇关于有没有办法防止杰克逊的反序列化现场?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆