How to serialize transient fields using jackson?

后端 未结 3 2011
不知归路
不知归路 2021-01-02 16:09

We use JSON serialization with Jackson to expose internal state of the system for debugging properties.

By default jackson does not serialize transient fields - but

3条回答
  •  囚心锁ツ
    2021-01-02 16:23

    You can create a custom getter for that transient field and use @XmlElement attribute. It doesn´t matter the name of that getter.

    For example:

    public class Person {
    
         @XmlTransient private String lastname;
    
         @XmlElement(name="lastname")
         public String getAnyNameOfMethod(){
             return lastname;
         }
    
    }
    

提交回复
热议问题