Serialization/Deserialization

Hi,

Until now I was using Nd4J version beta2 and had created the following Jackson config file in Kotlin, which worked fine:

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.module.SimpleModule
import org.nd4j.linalg.api.ndarray.INDArray
import org.nd4j.shade.serde.jackson.ndarray.NDArrayDeSerializer
import org.nd4j.shade.serde.jackson.ndarray.NDArraySerializer


class JacksonConfiguration {
	fun objectMapper(): ObjectMapper {
		return newObjectMapper
	}

	companion object {
		val newObjectMapper: ObjectMapper
			get() {
				val objectMapper = ObjectMapper()
				objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
				objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
				objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
				objectMapper.configure(
					DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL,
					true
				)
				objectMapper.configure(
					DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT,
					true
				)
				val module = SimpleModule()
				module.addDeserializer(INDArray::class.java, NDArrayDeSerializer())
				module.addSerializer(INDArray::class.java, NDArraySerializer())
				objectMapper.registerModule(module)
				return objectMapper
			}
	}
}

I just moved to the latest version and noticed that the Serializer and Deserializer have moved to

org.nd4j.serde.jackson.shaded.NDArrayDeSerializer
org.nd4j.serde.jackson.shaded.NDArraySerializer

The problem though is that when I use these imports, I cannot compile anymore and I am getting the error:

Type mismatch: inferred type is NDArrayDeSerializer but JsonDeserializer<out TypeVariable(T)!>! was expected

Is there a different way to use the serializer/deserializer with the new version? I cannot seem to find it…
Thank you!

@GeorgeK we use a shaded version of jackson and have upgraded that. Beta2 is years old at this point. I’m not quite sure where to begin with this without looking deeper. Do you mind filing an issue over on the github? Issues · eclipse/deeplearning4j · GitHub

I’m guessing it’s something simple but would need to take a closer look. Note that technically if you want to serialize ndarrays the toString() by itself is valid json as it ends up just being a json array of arrays. Maybe consider that for your use case as well.