How can I read JSON file and then put this into objects define in @Document - model for MongoDB. I'm looking for something like jackson object mapper in Java. It doesn't work here becouse Documen - model don't have empty constructor.
@Document(collection = "XXX")
class Room(@Id
private val id: String?,
private val name: String){there is toString() method}
class Application{
@Bean
fun imageProcess(repo: MongoRepository) = CommandLineRunner {
println("----------------Save customers!")
for (room in read("C:/Users/Desktop/new.json")) {
repo.save(room)
}
}
val mapper = ObjectMapper().registerModule(KotlinModule())
fun read(path: String): Array<Room>? {
var temp: Array<Room>? = null
try {
temp = mapper.readValue(File(path), Array<Room>::class.java)
} catch (ex: IOException) {
ex.printStackTrace()
}
return temp
}