Jackson not ignoring null objects in json array

Im using the JacksonConverterFactory from Retrofit2 to convert my json from the server to objects. But because im unsing realm the RealmList objects shouldn´t be null. I have tried to .getSerializationConfig().withSerializationInclusion(JsonInclude.Include.NON_NULL); but it looks like he still tries to add null values to the RealmList.

ObjectMapper mapper = new ObjectMapper();     mapper.getSerializationConfig().withSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
...
.addConverterFactory(JacksonConverterFactory.create(mapper)

the json looks like this

"items": [
    {
      "id": 8941,
      "size": 4
      "childs": [
        null,
        {
          "id": 32134,
          "count": 1
        },
        null,
        null
      ]
    },
    null,
    {
      "id": 8932,
      "size": 20
      "childs": [
        null,
        null,
        ...
      ]
    },
    {
      "id": 48715,
      "size": 20
    },
    null
  ]

The logcat:

Caused by: com.fasterxml.jackson.databind.JsonMappingException: RealmList does not accept null values (through reference chain: java.util.ArrayList[11]->my.package.myobject["items"]->io.realm.RealmList[4])

Answers


In the snippet you've provided JsonInclude.Include.NON_EMPTY is used. Did you really try JsonInclude.Include.NON_NULL ?


Need Your Help

CakePHP: paginating with search logic in a model

php cakephp pagination cakephp-appmodel

I'm having trouble paginating a search result. My setup is as follow.

Why when I unit test do I get coverage points with `final lazy val` but not `final val`?

java scala sbt scalatest

I have some code (project source available here - https://github.com/natemurthy/testing-final-vals):