package com.duooomi.ble.models import org.json.JSONObject data class VersionInfo( val version: String, val type: String ) { companion object { fun fromJson(json: JSONObject): VersionInfo { val typeValue = when { json.has("type") && json.get("type") is String -> json.getString("type") json.has("type") -> json.getInt("type").toString() else -> "" } return VersionInfo( version = json.optString("version", ""), type = typeValue ) } } }