I do have an object with a list of Files (java.io.File):
class NewRequestBody {
val files: MutableList<File> = ArrayList()
}
I need that object in my WorkManager
class, so I use Gson
to convert it to Json and add it to the WorkRequest.Builder
as InputData
:
val inputData = Data.Builder().putString(BODY_KEY, Gson().toJson(body)).build()
val myWorker = OneTimeWorkRequest.Builder(MyWorker::class.java)
.setInputData(inputData)
.build()
Then in my WorkManager class I'm converting it back:
val body = gson.fromJson(inputData.getString(BODY_KEY), NewRequestBody::class.java)
So far, with compileSdkVersion 30, that worked perfectly fine. The json hold this information for the files:
"files": [
{
"path": "path_to_the_file"
}
]
However, after updating the targetSdkVersion and compileSdkVersion to 33, that doesn't work anymore. The json now holds just an empty array:
"files": [
{}
]
Any idea what this is the case and how to fix it?