4

Let's say that we have a class that contains only one property:

data class MyClass(val map: Map<String, String?>)

As you can see, map property may contain null values, e.g.:

{
    "key1": "value1",
    "key2": null
}

Now if I use this instance of adapter to create JSON:

moshi.adapter(MyClass::class.java)

It will skip entries with null values (for the example above it will return a String like this: { "key1": "value1" }). The same thing happens if I add .serializeNulls() to the adapter instance.

Question

How can I force a Moshi adapter to take null into consideration?

Nominalista
  • 4,632
  • 11
  • 43
  • 102
  • 4
    Adding serializeNulls() works for me. Here's a test case to demonstrate. https://pastebin.com/raw/B5bXdbwr Can you provide a failing test case to show what you mean? – Eric Cochran Sep 07 '18 at 22:33

0 Answers0