Skip to content

Commit 29a1025

Browse files
committed
Accept null file size in AttachmentDto
1 parent 9933708 commit 29a1025

5 files changed

Lines changed: 36 additions & 3 deletions

File tree

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/DomainMapping.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ internal class DomainMapping(
579579
authorName = author_name,
580580
authorLink = author_link,
581581
fallback = fallback,
582-
fileSize = file_size,
582+
fileSize = file_size ?: 0,
583583
image = image,
584584
imageUrl = image_url,
585585
mimeType = mime_type,

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/AttachmentDto.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal data class AttachmentDto(
3333
val author_name: String?,
3434
val author_link: String?,
3535
val fallback: String?,
36-
val file_size: Int = 0,
36+
val file_size: Int? = 0,
3737
val image: String?,
3838
val image_url: String?,
3939
val mime_type: String?,

stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DomainMappingTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ internal class DomainMappingTest {
550550
authorName = attachmentDto.author_name,
551551
authorLink = attachmentDto.author_link,
552552
fallback = attachmentDto.fallback,
553-
fileSize = attachmentDto.file_size,
553+
fileSize = attachmentDto.file_size ?: 0,
554554
image = attachmentDto.image,
555555
imageUrl = attachmentDto.image_url,
556556
mimeType = attachmentDto.mime_type,

stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/AttachmentDtoAdapterTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,10 @@ internal class AttachmentDtoAdapterTest {
4949
val jsonString = parser.toJson(AttachmentDtoTestData.attachmentWithoutExtraData)
5050
jsonString.shouldEqualJson(AttachmentDtoTestData.jsonWithoutExtraData)
5151
}
52+
53+
@Test
54+
fun `Deserialize JSON attachment with null file_size`() {
55+
val attachment = parser.fromJson(AttachmentDtoTestData.jsonWithNullFileSize, AttachmentDto::class.java)
56+
attachment shouldBeEqualTo AttachmentDtoTestData.attachmentWithNullFileSize
57+
}
5258
}

stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/AttachmentDtoTestData.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@ internal object AttachmentDtoTestData {
6565
extraData = mapOf("draft" to true),
6666
)
6767

68+
@Language("JSON")
69+
val jsonWithNullFileSize =
70+
"""{
71+
"file_size": null
72+
}
73+
""".withoutWhitespace()
74+
val attachmentWithNullFileSize = AttachmentDto(
75+
asset_url = null,
76+
author_name = null,
77+
author_link = null,
78+
fallback = null,
79+
file_size = null,
80+
image = null,
81+
image_url = null,
82+
mime_type = null,
83+
name = null,
84+
og_scrape_url = null,
85+
text = null,
86+
thumb_url = null,
87+
title = null,
88+
title_link = null,
89+
type = null,
90+
original_width = null,
91+
original_height = null,
92+
extraData = emptyMap(),
93+
)
94+
6895
@Language("JSON")
6996
val jsonWithoutExtraData =
7097
"""{

0 commit comments

Comments
 (0)