Commit 480fc25d authored by Nihar Thakkar's avatar Nihar Thakkar

Merge branch 'ignore_unused_fields' into 'master'

Ignore unused response fields

See merge request !10
parents 1c853dca 0f891c09
Pipeline #23998 passed with stage
in 2 minutes and 56 seconds
......@@ -10,8 +10,8 @@ android {
applicationId "foundation.e.apps"
minSdkVersion 21
targetSdkVersion 27
versionCode 8
versionName "1.1.5"
versionCode 9
versionName "1.1.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
......@@ -18,9 +18,7 @@
package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import foundation.e.apps.application.model.data.FullData
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
......@@ -29,7 +27,7 @@ import foundation.e.apps.utils.Error
class AppDetailRequest(private val id: String) {
companion object {
private val reader = ObjectMapper().readerFor(Result::class.java)
private val reader = Common.getObjectMapper().readerFor(Result::class.java)
}
fun request(callback: (Error?, FullData?) -> Unit) {
......@@ -44,7 +42,6 @@ class AppDetailRequest(private val id: String) {
}
}
class Result @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
constructor(@JsonProperty("app") val app: FullData,
@JsonProperty("success") private val success: Boolean)
class Result @JsonCreator
constructor(@JsonProperty("app") val app: FullData)
}
......@@ -18,14 +18,12 @@
package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.databind.ObjectMapper
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
class AppDownloadedRequest(private val id: String) {
companion object {
private val reader = ObjectMapper().readerFor(Result::class.java)
private val reader = Common.getObjectMapper().readerFor(Result::class.java)
}
fun request() {
......@@ -39,6 +37,6 @@ class AppDownloadedRequest(private val id: String) {
}
}
class Result @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
class Result @JsonCreator
constructor()
}
......@@ -36,7 +36,7 @@ import java.lang.Exception
class HomeRequest {
companion object {
private val reader = ObjectMapper().readerFor(HomeResult::class.java)
private val reader = Common.getObjectMapper().readerFor(HomeResult::class.java)
}
fun request(callback: (Error?, HomeResult?) -> Unit) {
......@@ -51,9 +51,8 @@ class HomeRequest {
}
}
class HomeResult @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
constructor(@JsonProperty("success") private val success: Boolean,
@JsonProperty("home") private val home: SubHomeResult) {
class HomeResult @JsonCreator
constructor(@JsonProperty("home") private val home: SubHomeResult) {
fun getBannerApps(applicationManager: ApplicationManager, context: Context): ArrayList<Application> {
return ApplicationParser.parseToApps(applicationManager, context, home.bannerApps)
......@@ -69,7 +68,7 @@ class HomeRequest {
}
class SubHomeResult @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true) constructor() {
class SubHomeResult @JsonCreator constructor() {
val apps = LinkedHashMap<Category, ArrayList<BasicData>>()
lateinit var bannerApps: Array<BasicData>
......@@ -83,9 +82,6 @@ class HomeRequest {
data["package_name"] as String,
data["_id"] as String,
data["name"] as String,
0f,
data["last_modified"] as String,
data["latest_version"] as String,
data["latest_version_number"] as String?,
data["latest_downloaded_version"].toString(),
data["author"] as String,
......
......@@ -19,9 +19,7 @@ package foundation.e.apps.api
import android.content.Context
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import foundation.e.apps.application.model.Application
import foundation.e.apps.application.model.data.BasicData
import foundation.e.apps.applicationmanager.ApplicationManager
......@@ -34,7 +32,7 @@ import java.net.URLEncoder
class ListApplicationsRequest(private val category: String, private val page: Int, private val resultsPerPage: Int) {
companion object {
private val reader = ObjectMapper().readerFor(ListApplicationsResult::class.java)
private val reader = Common.getObjectMapper().readerFor(ListApplicationsResult::class.java)
}
fun request(callback: (Error?, ListApplicationsResult?) -> Unit) {
......@@ -49,10 +47,8 @@ class ListApplicationsRequest(private val category: String, private val page: In
}
}
class ListApplicationsResult @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
constructor(@JsonProperty("success") success: Boolean,
@JsonProperty("pages") val pages: Int,
@JsonProperty("apps") private val apps: Array<BasicData>) {
class ListApplicationsResult @JsonCreator
constructor(@JsonProperty("apps") private val apps: Array<BasicData>) {
fun getApplications(applicationManager: ApplicationManager, context: Context): ArrayList<Application> {
return ApplicationParser.parseToApps(applicationManager, context, apps)
......
......@@ -18,9 +18,7 @@
package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Error
import foundation.e.apps.utils.Constants
......@@ -29,7 +27,7 @@ import java.lang.Exception
class ListCategoriesRequest {
companion object {
private val reader = ObjectMapper().readerFor(ListCategoriesResult::class.java)
private val reader = Common.getObjectMapper().readerFor(ListCategoriesResult::class.java)
}
fun request(callback: (Error?, ListCategoriesResult?) -> Unit) {
......@@ -44,9 +42,8 @@ class ListCategoriesRequest {
}
}
class ListCategoriesResult @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
constructor(@JsonProperty("success") success: Boolean,
@JsonProperty("apps") val appsCategories: Array<String>,
class ListCategoriesResult @JsonCreator
constructor(@JsonProperty("apps") val appsCategories: Array<String>,
@JsonProperty("games") val gamesCategories: Array<String>)
}
......@@ -18,9 +18,7 @@
package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import foundation.e.apps.application.model.data.BasicData
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
......@@ -30,7 +28,7 @@ import java.net.URLEncoder
class PackageNameSearchRequest(private val packageName: String) {
companion object {
private val reader = ObjectMapper().readerFor(SearchResult::class.java)
private val reader = Common.getObjectMapper().readerFor(SearchResult::class.java)
}
fun request(callback: (Error?, SearchResult?) -> Unit) {
......@@ -45,11 +43,8 @@ class PackageNameSearchRequest(private val packageName: String) {
}
}
class SearchResult @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
constructor(@JsonProperty("success") success: Boolean,
@param:JsonProperty("pages") val pages: Int,
@param:JsonProperty("numberOfResults") val resultsNumber: Int,
@param:JsonProperty("apps") val appResults: Array<BasicData>) {
class SearchResult @JsonCreator
constructor(@param:JsonProperty("apps") val appResults: Array<BasicData>) {
fun findOneAppData(packageName: String): BasicData? {
appResults.forEach {
......
......@@ -19,15 +19,14 @@ package foundation.e.apps.api
import android.content.Context
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import foundation.e.apps.application.model.Application
import foundation.e.apps.applicationmanager.ApplicationManager
import foundation.e.apps.application.model.data.BasicData
import foundation.e.apps.utils.Error
import foundation.e.apps.utils.ApplicationParser
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Common.getObjectMapper
import foundation.e.apps.utils.Constants
import java.lang.Exception
import java.net.URLEncoder
......@@ -35,7 +34,7 @@ import java.net.URLEncoder
class SearchRequest(private val keyword: String, private val page: Int, private val resultsPerPage: Int) {
companion object {
private val reader = ObjectMapper().readerFor(SearchResult::class.java)
private val reader = getObjectMapper().readerFor(SearchResult::class.java)
}
fun request(callback: (Error?, SearchResult?) -> Unit) {
......@@ -50,11 +49,8 @@ class SearchRequest(private val keyword: String, private val page: Int, private
}
}
class SearchResult @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
constructor(@JsonProperty("success") success: Boolean,
@param:JsonProperty("pages") val pages: Int,
@param:JsonProperty("numberOfResults") val resultsNumber: Int,
@param:JsonProperty("apps") val appResults: Array<BasicData>) {
class SearchResult @JsonCreator
constructor(@param:JsonProperty("apps") val appResults: Array<BasicData>) {
fun getApplications(applicationManager: ApplicationManager, context: Context): List<Application> {
return ApplicationParser.parseToApps(applicationManager, context, appResults)
......
......@@ -20,7 +20,6 @@ package foundation.e.apps.application.model.data
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.application.model.Application
import foundation.e.apps.utils.Constants
......@@ -31,13 +30,10 @@ import foundation.e.apps.utils.ImagesLoader
import java.net.URL
import javax.net.ssl.HttpsURLConnection
class BasicData @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
class BasicData @JsonCreator
constructor(@param:JsonProperty("package_name") val packageName: String,
@param:JsonProperty("_id") val id: String,
@param:JsonProperty("name") val name: String,
@param:JsonProperty("search_score") val score: Float,
@param:JsonProperty("last_modified") val lastModified: String,
@param:JsonProperty("latest_version") val lastVersion: String,
@param:JsonProperty("latest_version_number") var lastVersionNumber: String?,
@param:JsonProperty("latest_downloaded_version") val latestDownloadableUpdate: String,
@param:JsonProperty("author") val author: String,
......@@ -87,7 +83,7 @@ constructor(@param:JsonProperty("package_name") val packageName: String,
}
@Synchronized
private fun loadIconSynced(): foundation.e.apps.utils.Error? {
private fun loadIconSynced(): Error? {
if (icon == null) {
try {
val url = URL(BASE_URL + "media/" + iconUri)
......@@ -99,7 +95,7 @@ constructor(@param:JsonProperty("package_name") val packageName: String,
urlConnection.disconnect()
} catch (e: Exception) {
e.printStackTrace()
return foundation.e.apps.utils.Error.UNKNOWN
return Error.UNKNOWN
}
}
return null
......
......@@ -19,39 +19,32 @@ package foundation.e.apps.application.model.data
import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.application.model.Version
import foundation.e.apps.categories.model.Category
class FullData @JsonCreator @JsonIgnoreProperties(ignoreUnknown = true)
class FullData @JsonCreator
constructor(
@JsonProperty("package_name") packageName: String,
@JsonProperty("_id") id: String,
@JsonProperty("name") name: String,
@JsonProperty("last_modified") lastModified: String,
@JsonProperty("latest_version") lastVersion: String,
@JsonProperty("latest_version_number") latestVersionNumber: String?,
@JsonProperty("latest_downloaded_version") latestDownloadableUpdate: String,
@JsonProperty("author") author: String,
@JsonProperty("icon_image_path") iconUri: String,
@JsonProperty("other_images_path") imagesUri: Array<String>,
@JsonProperty("category") categoryId: String,
@JsonProperty("created_on") val createdOn: String,
@JsonProperty("source") val source: String,
@JsonProperty("description") val description: String,
@JsonProperty("app_link") val appLink: String,
@JsonProperty("licence") val licence: String,
@JsonProperty("ratings") ratings: BasicData.Ratings?) {
var basicData = if (ratings == null) {
BasicData(packageName, id, name, -1f, lastModified, lastVersion,
latestVersionNumber, latestDownloadableUpdate, author, iconUri, imagesUri,
null, BasicData.Ratings(-1f, -1f), categoryId)
BasicData(packageName, id, name, latestVersionNumber, latestDownloadableUpdate, author,
iconUri, imagesUri, null,
BasicData.Ratings(-1f, -1f), categoryId)
} else {
BasicData(packageName, id, name, -1f, lastModified, lastVersion,
latestVersionNumber, latestDownloadableUpdate, author, iconUri, imagesUri,
ratings.privacyRating, ratings, categoryId)
BasicData(packageName, id, name, latestVersionNumber, latestDownloadableUpdate, author,
iconUri, imagesUri, ratings.privacyRating, ratings, categoryId)
}
private var latestVersion: Version? = null;
......
......@@ -21,6 +21,8 @@ import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.ConnectivityManager
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import java.net.URL
import java.util.concurrent.Executors
import javax.net.ssl.HttpsURLConnection
......@@ -79,4 +81,10 @@ object Common {
fun appHasLaunchActivity(context: Context, packageName: String): Boolean {
return (context.packageManager.getLaunchIntentForPackage(packageName) != null)
}
fun getObjectMapper(): ObjectMapper {
val objectMapper = ObjectMapper()
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
return objectMapper
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment