Skip to content

Commit

Permalink
Handle null is_archived flag on user details json.
Browse files Browse the repository at this point in the history
  • Loading branch information
sictiru committed Aug 30, 2023
1 parent e09a568 commit 8521118
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.newsblur

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.reflect.TypeToken
import com.newsblur.domain.Classifier
import com.newsblur.domain.Story
import com.newsblur.network.domain.StoriesResponse
import com.newsblur.serialization.BooleanTypeAdapter
import com.newsblur.serialization.ClassifierMapTypeAdapter
import com.newsblur.serialization.DateStringTypeAdapter
import com.newsblur.serialization.StoriesResponseTypeAdapter
import com.newsblur.serialization.StoryTypeAdapter
import org.junit.Test
import org.junit.runner.RunWith
import java.util.Date

@RunWith(AndroidJUnit4::class)
class ParsingTest {

@Test
fun test() {
val gson: Gson = GsonBuilder().apply {
registerTypeAdapter(Date::class.java, DateStringTypeAdapter())
registerTypeAdapter(Boolean::class.java, BooleanTypeAdapter())
registerTypeAdapter(Boolean::class.javaPrimitiveType, BooleanTypeAdapter())
registerTypeAdapter(Story::class.java, StoryTypeAdapter())
registerTypeAdapter(StoriesResponse::class.java, StoriesResponseTypeAdapter())
registerTypeAdapter(object : TypeToken<Map<String?, Classifier?>?>() {}.type, ClassifierMapTypeAdapter())
}.create()

val input = """""".trimIndent()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ public FeedFolderResponse(String json, Gson gson) {
if (userProfile != null) {
JsonObject profile = (JsonObject) userProfile;
this.isPremium = profile.get("is_premium").getAsBoolean();
this.isArchive = profile.get("is_archive").getAsBoolean();
this.premiumExpire = profile.get("premium_expire").getAsLong();
if (asJsonObject.has("is_archive")) {
this.isArchive = profile.get("is_archive").getAsBoolean();
}
}

JsonElement starredCountElement = asJsonObject.get("starred_count");
Expand Down

0 comments on commit 8521118

Please sign in to comment.