@Autowired
@JvmField
var obj: Obj? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
ARouter.getInstance().inject(this)
val first = obj?.first
val second = obj?.second
}
@Route(path = "/service/json")
class JsonServiceImpl : SerializationService {
override fun init(context: Context?) {
}
override fun <T> json2Object(input: String?, clazz: Class<T>?): T {
return JSON.parseObject(input, clazz)
}
override fun object2Json(instance: Any?): String {
return JSON.toJSONString(instance)
}
override fun <T> parseObject(input: String?, clazz: Type?): T {
return JSON.parseObject(input, clazz)
}
}
public class TestObject {
public String f,s;
public TestObject() {
}
public TestObject(String f, String s) {
this.f = f;
this.s = s;
}
}
data class TestObj(
var f: String? = null,
var s: String? = null
)
/**
* 使用Gson作为序列化与反序列化
*/
@Route(path = "/service/json")
class JsonServiceImpl : SerializationService {
private val GSON by lazy { Gson() }
override fun init(context: Context?) {
}
override fun <T> json2Object(input: String?, clazz: Class<T>?): T {
return GSON.fromJson(input, clazz)
}
override fun object2Json(instance: Any?): String {
return GSON.toJson(instance)
}
override fun <T> parseObject(input: String?, clazz: Type?): T {
return GSON.fromJson(input, clazz)
}
}
/**
* 使用FastJson进行序列化与反序列化
*/
@Route(path = "/service/json")
class JsonServiceImpl : SerializationService {
override fun init(context: Context?) {
}
override fun <T> json2Object(input: String?, clazz: Class<T>?): T {
return JSON.parseObject(input, clazz)
}
override fun object2Json(instance: Any?): String {
return JSON.toJSONString(instance)
}
override fun <T> parseObject(input: String?, clazz: Type?): T {
return JSON.parseObject(input, clazz)
}
}