From d4c1890c4de6a863d75de9e1d5cb0f782fcd8306 Mon Sep 17 00:00:00 2001 From: Xiaowei Zhu <33129495+zhu-xiaowei@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:21:08 +0800 Subject: [PATCH] fix: change user attribute to JSONObject (#50) Co-authored-by: xiaoweii --- .../aws/solution/clickstream/client/AnalyticsClient.java | 4 ++-- .../aws/solution/clickstream/AnalyticsClientTest.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/clickstream/src/main/java/software/aws/solution/clickstream/client/AnalyticsClient.java b/clickstream/src/main/java/software/aws/solution/clickstream/client/AnalyticsClient.java index 7837e2f..b4d83f5 100644 --- a/clickstream/src/main/java/software/aws/solution/clickstream/client/AnalyticsClient.java +++ b/clickstream/src/main/java/software/aws/solution/clickstream/client/AnalyticsClient.java @@ -251,10 +251,10 @@ private JSONObject getSimpleUserAttribute() { JSONObject userAttribute = new JSONObject(); try { userAttribute.put(Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP, - allUserAttributes.getString(Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP)); + allUserAttributes.getJSONObject(Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP)); if (allUserAttributes.has(Event.ReservedAttribute.USER_ID)) { userAttribute.put(Event.ReservedAttribute.USER_ID, - allUserAttributes.getString(Event.ReservedAttribute.USER_ID)); + allUserAttributes.getJSONObject(Event.ReservedAttribute.USER_ID)); } } catch (final JSONException jsonException) { LOG.error("Could not create Json object of simpleUserAttribute. error: " + jsonException.getMessage()); diff --git a/clickstream/src/test/java/software/aws/solution/clickstream/AnalyticsClientTest.java b/clickstream/src/test/java/software/aws/solution/clickstream/AnalyticsClientTest.java index 599f783..680c560 100644 --- a/clickstream/src/test/java/software/aws/solution/clickstream/AnalyticsClientTest.java +++ b/clickstream/src/test/java/software/aws/solution/clickstream/AnalyticsClientTest.java @@ -466,6 +466,8 @@ public void testCreateEventWithoutCustomUserAttributes() throws JSONException { Assert.assertTrue(user.has(Event.ReservedAttribute.USER_FIRST_TOUCH_TIMESTAMP)); Assert.assertFalse(user.has("userName")); Assert.assertFalse(user.has("userAge")); + JSONObject userIdObject = user.getJSONObject(Event.ReservedAttribute.USER_ID); + Assert.assertEquals("123", userIdObject.getString("value")); } /**