Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ package com.usercentrics.sdk.flutter.serializer

import com.usercentrics.sdk.v2.settings.data.ConsentDisclosure
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureObject
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureSDK

internal fun ConsentDisclosureObject?.serializer(): Any? {
if (this == null) {
return null
}
return disclosures.map { it.serializer() }
return mapOf(
"disclosures" to disclosures.map { it.serializer() },
"sdks" to sdks.map { it.serializer() }
)
}

private fun ConsentDisclosureSDK.serializer(): Map<String, Any> {
return mapOf(
"name" to name,
"use" to use
)
}

internal fun ConsentDisclosure.serializer(): Any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ internal object GetCMPDataMock {
domain = "domain",
description = "description",
)
)
),
sdks = listOf()
),
isHidden = false,
)
Expand Down Expand Up @@ -709,17 +710,20 @@ internal object GetCMPDataMock {
"disableLegalBasis" to false,
"isEssential" to false,
"technologyUsed" to listOf("Cookies", "Pixel Tags"),
"deviceStorage" to listOf(
mapOf(
"identifier" to "identifier",
"type" to "APP",
"name" to "name",
"maxAgeSeconds" to 123123L,
"cookieRefresh" to true,
"purposes" to listOf(1, 2, 3),
"domain" to "domain",
"description" to "description",
)
"deviceStorage" to mapOf(
"disclosures" to listOf(
mapOf(
"identifier" to "identifier",
"type" to "APP",
"name" to "name",
"maxAgeSeconds" to 123123L,
"cookieRefresh" to true,
"purposes" to listOf(1, 2, 3),
"domain" to "domain",
"description" to "description",
)
),
"sdks" to emptyList<Map<String, Any>>()
),
"isHidden" to false,
)
Expand Down
5 changes: 4 additions & 1 deletion ios/Classes/Serializer/ConsentDisclosureSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import Usercentrics

extension ConsentDisclosureObject {
func serialize() -> Any {
return self.disclosures.map { $0.serialize() }
return [
"disclosures": self.disclosures.map { $0.serialize() },
"sdks": self.sdks.map { ["name": $0.name, "use": $0.use] }
] as [String: Any]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,48 @@ class ConsentDisclosureObjectSerializer {
return null;
}

List<dynamic> values = value ?? [];
// New format: { disclosures: [...], sdks: [...] }
if (value is Map) {
final disclosures = value['disclosures'] as List<dynamic>? ?? [];
final sdks = value['sdks'] as List<dynamic>? ?? [];
if (disclosures.isEmpty && sdks.isEmpty) {
return null;
}
return ConsentDisclosureObject(
disclosures: disclosures
.map<ConsentDisclosure>(
(e) => ConsentDisclosureSerializer.deserialize(e))
.toList(),
sdks: sdks
.map<ConsentDisclosureSDK>(
(e) => ConsentDisclosureSDKSerializer.deserialize(e))
.toList(),
);
}

// Legacy format: array of disclosures
final values = value is List ? value : [];
if (values.isEmpty) {
return null;
}
return ConsentDisclosureObject(
disclosures: (value ?? [])
disclosures: values
.map<ConsentDisclosure>(
(e) => ConsentDisclosureSerializer.deserialize(e))
.toList(),
);
}
}

class ConsentDisclosureSDKSerializer {
static ConsentDisclosureSDK deserialize(dynamic value) {
return ConsentDisclosureSDK(
name: value['name'] ?? '',
use: value['use'] ?? '',
);
}
}

class ConsentDisclosureSerializer {
static ConsentDisclosure deserialize(dynamic value) {
return ConsentDisclosure(
Expand Down
29 changes: 26 additions & 3 deletions lib/src/model/consent_disclosure.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
import 'package:flutter/foundation.dart';

class ConsentDisclosureSDK {
const ConsentDisclosureSDK({required this.name, required this.use});

final String name;
final String use;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ConsentDisclosureSDK &&
runtimeType == other.runtimeType &&
name == other.name &&
use == other.use;

@override
int get hashCode => Object.hash(name, use);
}

class ConsentDisclosureObject {
const ConsentDisclosureObject({required this.disclosures});
const ConsentDisclosureObject({
required this.disclosures,
this.sdks = const [],
});

final List<ConsentDisclosure> disclosures;
final List<ConsentDisclosureSDK> sdks;

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ConsentDisclosureObject &&
runtimeType == other.runtimeType &&
listEquals(disclosures, other.disclosures);
listEquals(disclosures, other.disclosures) &&
listEquals(sdks, other.sdks);

@override
int get hashCode => disclosures.hashCode;
int get hashCode => Object.hash(disclosures, sdks);
}

class ConsentDisclosure {
Expand Down
Loading
Loading