Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed serialization of strings twice #390

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -95,7 +95,12 @@ public static String getDeviceId(Application application) {
}

desusai7 marked this conversation as resolved.
Show resolved Hide resolved
public static Map<String, Object> convertToMap(Object obj) {
String json = RudderGson.serialize(obj);
String json;
if (obj instanceof String) {
json = (String) obj;
} else {
json = RudderGson.serialize(obj);
}
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
if (json == null) {
return new HashMap<>();
}
Expand All @@ -108,7 +113,13 @@ public static Map<String, Object> convertToMap(Object obj) {


public static List<Map<String, Object>> convertToList(Object obj) {
String json = RudderGson.serialize(obj);
String json;
if (obj instanceof String) {
json = (String) obj;
} else {
json = RudderGson.serialize(obj);
}

if (json == null) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rudderstack.android.sdk.core;

import static org.hamcrest.MatcherAssert.assertThat;

import com.rudderstack.android.sdk.core.util.Utils;

import org.junit.Test;

import java.util.List;
import java.util.Map;

public class UtilsTest {
@Test
public void testStringConversiontToMap() {
String rudderTraits = "{\"dirty\":{\"general\":45.0,\"minValue\":4.9E-324,\"maxValue\":1.7976931348623157E308,\"double\":45.0,\"positiveInfinity\":\"Infinity\",\"nan\":\"NaN\",\"float\":45.0,\"list\":[\"Infinity\",\"-Infinity\",1.7976931348623157E308,4.9E-324,\"NaN\",45.0,45.0],\"map\":{\"general\":45.0,\"minValue\":4.9E-324,\"maxValue\":1.7976931348623157E308,\"double\":45.0,\"positiveInfinity\":\"Infinity\",\"nan\":\"NaN\",\"negativeInfinity\":\"-Infinity\"},\"long\":45.0,\"int\":45.0,\"negativeInfinity\":\"-Infinity\"},\"anonymousId\":\"c5ee2cf1-97a3-4744-80fc-faabce7a7e51\",\"name\":\"Mr. User1\",\"id\":\"new user 2\",\"userId\":\"new user 2\",\"email\":\"[email protected]\"}";
Map<String,Object> map = Utils.convertToMap(rudderTraits);
assertThat("Map should not be empty", map.size() > 0);
}

@Test
public void testStringConversionToArray() {
String externalIds = "[{\"id\":\"idValue\",\"type\":\"idTYpe\"}]";
List<Map<String, Object>> list = Utils.convertToList(externalIds);
assertThat("List should not be empty", list.size() > 0);
}
}
Loading