Skip to content

Commit 63aa089

Browse files
authored
fix: handle empty data (#105)
1 parent fc446f1 commit 63aa089

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/main/java/io/getstream/core/models/Data.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public <T> Data from(T data) {
5151

5252
public Data from(Map<String, Object> map) {
5353
checkNotNull(data, "Can't extract data from null");
54+
if (map == null || map.isEmpty()) {
55+
return this;
56+
}
5457

5558
for (Map.Entry<String, Object> entry : map.entrySet()) {
5659
set(entry.getKey(), entry.getValue());

src/test/java/io/getstream/core/utils/SerializationTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static io.getstream.core.utils.Serialization.*;
44
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertNotNull;
56

67
import com.fasterxml.jackson.core.type.TypeReference;
78
import com.google.common.collect.ImmutableMap;
@@ -13,6 +14,7 @@
1314
import io.getstream.core.models.CollectionData;
1415
import io.getstream.core.models.EnrichedActivity;
1516
import io.getstream.core.models.FeedID;
17+
import io.getstream.core.models.Reaction;
1618
import java.io.ByteArrayInputStream;
1719
import java.nio.charset.Charset;
1820
import java.text.SimpleDateFormat;
@@ -209,6 +211,16 @@ public void emptyMapDeserialization() throws Exception {
209211
fromJSON(new ByteArrayInputStream(activity.getBytes(Charset.forName("UTF-8"))), type);
210212
}
211213

214+
@Test
215+
public void emptyDataDeserialization() throws Exception {
216+
String reaction = "{ \"data\": {} }";
217+
TypeReference<Reaction> type = new TypeReference<Reaction>() {};
218+
219+
Reaction result =
220+
fromJSON(new ByteArrayInputStream(reaction.getBytes(Charset.forName("UTF-8"))), type);
221+
assertNotNull(result);
222+
}
223+
212224
@Test
213225
public void creatorAndAnySetterDeserialization() throws Exception {
214226
String data = "{\"id\":\"id-thing\",\"value\":1,\"extra\":{\"test\":\"test\"}}";

0 commit comments

Comments
 (0)