Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop Gson exposure by making MastodonClient.getSerializer internal #86

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ object MockClient {
}
.build()
every { client.get(ofType<String>(), any()) } returns response
every { client.getSerializer() } returns Gson()

// mocking function that is internal in MastodonClient
every { client["getSerializer"]() } returns Gson()

return client
}
}
3 changes: 2 additions & 1 deletion bigbone/src/main/kotlin/social/bigbone/MastodonClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ private constructor(
PATCH
}

open fun getSerializer() = gson
@PublishedApi
internal fun getSerializer() = gson

open fun getInstanceName() = instanceName

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package social.bigbone.sample;

import com.google.gson.Gson;
import social.bigbone.MastodonClient;
import social.bigbone.MastodonRequest;
import social.bigbone.Parameter;
Expand Down Expand Up @@ -95,7 +96,7 @@ private static MastodonRequest<AccessToken> postUserNameAndPassword(
.append("grant_type", "password");
return new MastodonRequest<>(
() -> client.post("oauth/token", parameters),
s -> client.getSerializer().fromJson(s, AccessToken.class)
s -> new Gson().fromJson(s, AccessToken.class)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package social.bigbone.sample

import com.google.gson.Gson
import social.bigbone.MastodonClient
import social.bigbone.MastodonRequest
import social.bigbone.Parameter
Expand Down Expand Up @@ -109,7 +110,7 @@ object Authenticator {
client.post("oauth/token", parameters)
},
{
client.getSerializer().fromJson(it, AccessToken::class.java)
Gson().fromJson(it, AccessToken::class.java)
}
)
}
Expand Down