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])

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

I also tried gson, but for gson he is doing the same
Im using RealmList<MyObject>
i could aslo override the RealmList and remove the exception

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.