JsonIgnoreProperties not working

后端 未结 4 1727
故里飘歌
故里飘歌 2021-01-07 17:54

I have the following simple class:

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties({ \"thirdField\" })
public class Message          


        
相关标签:
4条回答
  • 2021-01-07 18:22

    You've mixed different versions of Jackson. Notice that you import JsonIgnoreProperties from org.codehaus.jackson.annotate (version 1.x) while you're using ObjectMapper from com.fasterxml.jackson.databind (version 2.x).

    0 讨论(0)
  • 2021-01-07 18:22

    I found a Solution to this. Try to add

    @JsonSerialize(include= JsonSerialize.Inclusion.NON_EMPTY)
    

    About your class

    @JsonSerialize(include= JsonSerialize.Inclusion.NON_EMPTY)
    class ResponseModel {
     //your properties here
     @JsonIgnoreProperties("messageList","contactList","sender")
        var contactList= ArrayList<ContactModel>()
    }
    

    That will solve your issue buddy.

    0 讨论(0)
  • 2021-01-07 18:33

    It didn't work for me any of the above answers, i found a workaround that I have reinitialized the object and values (copied the object).

    0 讨论(0)
  • 2021-01-07 18:42

    Try using the last Jackson version (2.4):

    import com.fasterxml.jackson.annotation.JsonIgnoreProperties
    @JsonIgnoreProperties({"id"})
    

    Here you can find an example where it's implement using version 2.4: http://www.ibm.com/developerworks/java/library/j-hangman-app/index.html

    0 讨论(0)
提交回复
热议问题