fromJson static method

Session fromJson(
  1. dynamic json
)

Implementation

static Session fromJson(dynamic json) {
  dynamic jsonData;
  try {
        String jsonDataString = json.toString();
        jsonData = jsonDecode(jsonDataString);
  } catch(e){
    jsonData = json;
  }

  var widgetUserAgentJson = jsonData['widgetUserAgent'];
  widgetUserAgentJson ??= jsonData['WidgetUserAgent'];

  var riskAnalyticsJson = jsonData['riskAnalytics'];
  WidgetUserAgent? widgetUserAgent;
  RiskAnalytics? riskAnalytics;

  if (widgetUserAgentJson != null) {
    widgetUserAgent = WidgetUserAgent.fromJson(widgetUserAgentJson);
  }

  if (riskAnalyticsJson != null) {
    riskAnalytics = RiskAnalytics.fromJson(riskAnalyticsJson);
  }

  String? ipaddressMobile = jsonData['iPAddressMobile'] as String?;
  ipaddressMobile ??= jsonData['IPAddressMobile'] as String?;

  String? ipaddressWidget = jsonData['iPAddressWidget'] as String?;
  ipaddressWidget ??= jsonData['IPAddressWidget'] as String?;

  return Session(
    jsonData['widgetOrigin'] as String?,
    jsonData['sessionId'] as String,
    widgetUserAgent,
    ipaddressMobile ?? "",
    ipaddressWidget ?? "",
    riskAnalytics,
    jsonData['publicUserId'] as String?,
  );
}