This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2019-07-22T03:27:42.601Z","extensionVersion":"v3.4.0"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static <T> T getMyDataModel(Context context, @RawRes int jsonFileRes) { | |
Type type = new TypeToken<T>(){}.getType(); | |
Gson gson = new Gson(); | |
InputStream inputStream = context.getResources().openRawResource(jsonFileRes); | |
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream)); | |
return gson.fromJson(bufferReader, type); | |
} | |
// วิธีเรียกใช้ | |
GenericJava.getMyDataModel<MyDataModel>(this, R.raw.json_text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T getJsonClassParameter(Context context, @RawRes int jsonFileRes, Class<T> classType) { | |
Gson gson = new Gson(); | |
InputStream inputStream = context.getResources().openRawResource(jsonFileRes); | |
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream)); | |
return gson.fromJson(bufferReader, classType); | |
} | |
// วิธีเรียกใช้ | |
GenericJava.getJsonClassParameter(this, R.raw.json_text, MyDataModel.class) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun MyDataModel Context.getJsonFixModelClassKotlin(@RawRes jsonFileRes: Int): MyDataModel { | |
val inputStream = this.resources.openRawResource(jsonFileRes) | |
val bufferReader = BufferedReader(InputStreamReader(inputStream)) | |
return gson.fromJson(bufferReader, MyDataModel::class.java) | |
} | |
// วิธีเรียกใช้ | |
getJsonFixModelClassKotlin(R.raw.json_text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Context.getJsonGenericKotlin(@RawRes jsonFileRes: Int): T { | |
val inputStream = this.resources.openRawResource(jsonFileRes) | |
val bufferReader = BufferedReader(InputStreamReader(inputStream)) | |
return gson.fromJson(bufferReader, T::class.java) | |
} | |
// วิธีเรียกใช้ | |
getJsonGenericKotlin<MyDataModel>(R.raw.json_text) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T> Context.getJsonGenericKotlin(@RawRes jsonFileRes: Int): T { | |
val inputStream = this.resources.openRawResource(jsonFileRes) | |
val bufferReader = BufferedReader(InputStreamReader(inputStream)) | |
return gson.fromJson(bufferReader, T::class.java) | |
} | |
// วิธีเรียกใช้ | |
getJsonGenericKotlin<MyDataModel>(R.raw.json_text) |
OlderNewer