MoshiReader.kt 757 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package de.h_da.fbi.smebt.intentfinder.server.sources

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory

class MoshiReader(var configType:String) {
    private val moshi = Moshi.Builder()
        .addLast(KotlinJsonAdapterFactory())
        .build()


    private fun setAdapter():JsonAdapter<out Any>{
        //Differ  between url and docx
        if(configType == "url") {
            return moshi.adapter(JSONUrlConfig::class.java)
        }
        else {
            return moshi.adapter(JSONDocxConfig::class.java)
        }

    }

    @Throws(Exception::class)
    fun getObjectFromJson(json: String): Any? {

        return setAdapter().fromJson(json)
    }
}