1

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])
Fabian
  • 960
  • 13
  • 26

1 Answers1

2

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

Oleh Novikov
  • 558
  • 5
  • 17