@@ -23,6 +23,7 @@ import com.opennotes.notes.data.repository.JsonHandler
2323import com.opennotes.notes.domain.model.Note
2424import com.opennotes.notes.domain.repository.NoteRepository
2525import com.opennotes.notes.domain.util.ImportResult
26+ import kotlinx.serialization.json.*
2627
2728class ImportUseCases (
2829 private val repository : NoteRepository ,
@@ -43,9 +44,9 @@ class ImportUseCases(
4344 }
4445
4546 // Deserialize with validation - catch invalid JSON first
46- val rawNotes: List < Map < String , Any ?>> =
47+ val rawNotes =
4748 try {
48- jsonHandler.fromJsonToNoteMapList (notesJson)
49+ jsonHandler.parseToJsonArray (notesJson)
4950 } catch (e: Exception ) {
5051 return ImportResult .Error (" Invalid JSON format: ${e.message} " )
5152 }
@@ -56,11 +57,12 @@ class ImportUseCases(
5657
5758 // Validate and construct trusted Note objects
5859 val validNotes =
59- rawNotes.mapNotNull { rawNote ->
60- val title = (rawNote[" title" ] as ? String )?.trim()
61- val content = (rawNote[" content" ] as ? String )?.trim()
62- val timestamp = (rawNote[" timestamp" ] as ? Number )?.toLong()
63- val color = (rawNote[" color" ] as ? Number )?.toInt()
60+ rawNotes.mapNotNull { element ->
61+ val rawNote = element as ? JsonObject ? : return @mapNotNull null
62+ val title = rawNote[" title" ]?.jsonPrimitive?.contentOrNull?.trim()
63+ val content = rawNote[" content" ]?.jsonPrimitive?.contentOrNull?.trim()
64+ val timestamp = rawNote[" timestamp" ]?.jsonPrimitive?.longOrNull
65+ val color = rawNote[" color" ]?.jsonPrimitive?.intOrNull
6466
6567 // Only create Note if all required fields are present and valid
6668 if ((title?.isNotBlank() == true || content?.isNotBlank() == true ) &&
0 commit comments