don't use gson's reflection serialization on non RuneLite classes
java >=16 disallows access to most private fields which makes these fail with the reflection type adapter
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
*/
|
||||
package net.runelite.client;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.name.Names;
|
||||
@@ -51,6 +52,7 @@ import net.runelite.client.plugins.PluginManager;
|
||||
import net.runelite.client.task.Scheduler;
|
||||
import net.runelite.client.util.DeferredEventBus;
|
||||
import net.runelite.client.util.ExecutorServiceExceptionLogger;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import net.runelite.http.api.chat.ChatClient;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@@ -86,6 +88,8 @@ public class RuneLiteModule extends AbstractModule
|
||||
bind(PluginManager.class);
|
||||
bind(SessionManager.class);
|
||||
|
||||
bind(Gson.class).toInstance(RuneLiteAPI.GSON);
|
||||
|
||||
bind(Callbacks.class).to(Hooks.class);
|
||||
|
||||
bind(EventBus.class)
|
||||
|
||||
@@ -64,6 +64,7 @@ public class SessionManager
|
||||
private final WSClient wsClient;
|
||||
private final File sessionFile;
|
||||
private final AccountClient accountClient;
|
||||
private final Gson gson;
|
||||
|
||||
@Inject
|
||||
private SessionManager(
|
||||
@@ -71,13 +72,15 @@ public class SessionManager
|
||||
ConfigManager configManager,
|
||||
EventBus eventBus,
|
||||
WSClient wsClient,
|
||||
OkHttpClient okHttpClient)
|
||||
OkHttpClient okHttpClient,
|
||||
Gson gson)
|
||||
{
|
||||
this.configManager = configManager;
|
||||
this.eventBus = eventBus;
|
||||
this.wsClient = wsClient;
|
||||
this.sessionFile = sessionfile;
|
||||
this.accountClient = new AccountClient(okHttpClient);
|
||||
this.gson = gson;
|
||||
|
||||
eventBus.register(this);
|
||||
}
|
||||
@@ -94,7 +97,7 @@ public class SessionManager
|
||||
|
||||
try (FileInputStream in = new FileInputStream(sessionFile))
|
||||
{
|
||||
session = new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), AccountSession.class);
|
||||
session = gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), AccountSession.class);
|
||||
|
||||
log.debug("Loaded session for {}", session.getUsername());
|
||||
}
|
||||
@@ -124,7 +127,7 @@ public class SessionManager
|
||||
|
||||
try (Writer fw = new OutputStreamWriter(new FileOutputStream(sessionFile), StandardCharsets.UTF_8))
|
||||
{
|
||||
new Gson().toJson(accountSession, fw);
|
||||
gson.toJson(accountSession, fw);
|
||||
|
||||
log.debug("Saved session to {}", sessionFile);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package net.runelite.client.externalplugins;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -59,11 +60,13 @@ import okio.BufferedSource;
|
||||
public class ExternalPluginClient
|
||||
{
|
||||
private final OkHttpClient okHttpClient;
|
||||
private final Gson gson;
|
||||
|
||||
@Inject
|
||||
private ExternalPluginClient(OkHttpClient okHttpClient)
|
||||
private ExternalPluginClient(OkHttpClient okHttpClient, Gson gson)
|
||||
{
|
||||
this.okHttpClient = okHttpClient;
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
public List<ExternalPluginManifest> downloadManifest() throws IOException, VerificationException
|
||||
@@ -94,7 +97,7 @@ public class ExternalPluginClient
|
||||
throw new VerificationException("Unable to verify external plugin manifest");
|
||||
}
|
||||
|
||||
return RuneLiteAPI.GSON.fromJson(new String(data, StandardCharsets.UTF_8),
|
||||
return gson.fromJson(new String(data, StandardCharsets.UTF_8),
|
||||
new TypeToken<List<ExternalPluginManifest>>()
|
||||
{
|
||||
}.getType());
|
||||
@@ -156,7 +159,7 @@ public class ExternalPluginClient
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(RequestBody.create(RuneLiteAPI.JSON, RuneLiteAPI.GSON.toJson(plugins)))
|
||||
.post(RequestBody.create(RuneLiteAPI.JSON, gson.toJson(plugins)))
|
||||
.build();
|
||||
|
||||
okHttpClient.newCall(request).enqueue(new Callback()
|
||||
@@ -190,7 +193,7 @@ public class ExternalPluginClient
|
||||
}
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
|
||||
return gson.fromJson(new InputStreamReader(res.body().byteStream()), new TypeToken<Map<String, Integer>>(){}.getType());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
catch (JsonSyntaxException ex)
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.MediaType;
|
||||
@@ -47,11 +46,13 @@ public class CrowdsourcingManager
|
||||
{
|
||||
private static final String CROWDSOURCING_BASE = "https://crowdsource.runescape.wiki/runelite";
|
||||
private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
|
||||
private static final Gson GSON = RuneLiteAPI.GSON;
|
||||
|
||||
@Inject
|
||||
private OkHttpClient okHttpClient;
|
||||
|
||||
@Inject
|
||||
private Gson gson;
|
||||
|
||||
private List<Object> data = new ArrayList<>();
|
||||
|
||||
public void storeEvent(Object event)
|
||||
@@ -77,7 +78,7 @@ public class CrowdsourcingManager
|
||||
|
||||
Request r = new Request.Builder()
|
||||
.url(CROWDSOURCING_BASE)
|
||||
.post(RequestBody.create(JSON, GSON.toJson(temp)))
|
||||
.post(RequestBody.create(JSON, gson.toJson(temp)))
|
||||
.build();
|
||||
|
||||
okHttpClient.newCall(r).enqueue(new Callback()
|
||||
|
||||
@@ -128,7 +128,6 @@ public class GrandExchangePlugin extends Plugin
|
||||
|
||||
private static final String BUY_LIMIT_GE_TEXT = "<br>Buy limit: ";
|
||||
private static final String BUY_LIMIT_KEY = "buylimit";
|
||||
private static final Gson GSON = new Gson();
|
||||
private static final Duration BUY_LIMIT_RESET = Duration.ofHours(4);
|
||||
|
||||
static final String SEARCH_GRAND_EXCHANGE = "Search Grand Exchange";
|
||||
@@ -183,6 +182,9 @@ public class GrandExchangePlugin extends Plugin
|
||||
@Inject
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Inject
|
||||
private Gson gson;
|
||||
|
||||
private Widget grandExchangeText;
|
||||
private Widget grandExchangeItem;
|
||||
private String grandExchangeExamine;
|
||||
@@ -253,12 +255,12 @@ public class GrandExchangePlugin extends Plugin
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GSON.fromJson(offer, SavedOffer.class);
|
||||
return gson.fromJson(offer, SavedOffer.class);
|
||||
}
|
||||
|
||||
private void setOffer(int slot, SavedOffer offer)
|
||||
{
|
||||
configManager.setRSProfileConfiguration("geoffer", Integer.toString(slot), GSON.toJson(offer));
|
||||
configManager.setRSProfileConfiguration("geoffer", Integer.toString(slot), gson.toJson(offer));
|
||||
}
|
||||
|
||||
private void deleteOffer(int slot)
|
||||
|
||||
@@ -73,8 +73,6 @@ public class GroundMarkerPlugin extends Plugin
|
||||
private static final String WALK_HERE = "Walk here";
|
||||
private static final String REGION_PREFIX = "region_";
|
||||
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final List<ColorTileMarker> points = new ArrayList<>();
|
||||
|
||||
@@ -105,6 +103,9 @@ public class GroundMarkerPlugin extends Plugin
|
||||
@Inject
|
||||
private GroundMarkerSharingManager sharingManager;
|
||||
|
||||
@Inject
|
||||
private Gson gson;
|
||||
|
||||
void savePoints(int regionId, Collection<GroundMarkerPoint> points)
|
||||
{
|
||||
if (points == null || points.isEmpty())
|
||||
@@ -113,7 +114,7 @@ public class GroundMarkerPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
String json = GSON.toJson(points);
|
||||
String json = gson.toJson(points);
|
||||
configManager.setConfiguration(CONFIG_GROUP, REGION_PREFIX + regionId, json);
|
||||
}
|
||||
|
||||
@@ -126,7 +127,7 @@ public class GroundMarkerPlugin extends Plugin
|
||||
}
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
return GSON.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||
return gson.fromJson(json, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
import net.runelite.client.menus.MenuManager;
|
||||
import net.runelite.client.menus.WidgetMenuOption;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
|
||||
@Slf4j
|
||||
class GroundMarkerSharingManager
|
||||
@@ -61,22 +60,23 @@ class GroundMarkerSharingManager
|
||||
private static final WidgetMenuOption EXPORT_MARKERS_OPTION = new WidgetMenuOption("Export", "Ground Markers", WORLD_MAP_OPTION);
|
||||
private static final WidgetMenuOption IMPORT_MARKERS_OPTION = new WidgetMenuOption("Import", "Ground Markers", WORLD_MAP_OPTION);
|
||||
|
||||
private static final Gson GSON = RuneLiteAPI.GSON;
|
||||
|
||||
private final GroundMarkerPlugin plugin;
|
||||
private final Client client;
|
||||
private final MenuManager menuManager;
|
||||
private final ChatMessageManager chatMessageManager;
|
||||
private final ChatboxPanelManager chatboxPanelManager;
|
||||
private final Gson gson;
|
||||
|
||||
@Inject
|
||||
private GroundMarkerSharingManager(GroundMarkerPlugin plugin, Client client, MenuManager menuManager, ChatMessageManager chatMessageManager, ChatboxPanelManager chatboxPanelManager)
|
||||
private GroundMarkerSharingManager(GroundMarkerPlugin plugin, Client client, MenuManager menuManager,
|
||||
ChatMessageManager chatMessageManager, ChatboxPanelManager chatboxPanelManager, Gson gson)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.client = client;
|
||||
this.menuManager = menuManager;
|
||||
this.chatMessageManager = chatMessageManager;
|
||||
this.chatboxPanelManager = chatboxPanelManager;
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
void addMenuOptions()
|
||||
@@ -135,7 +135,7 @@ class GroundMarkerSharingManager
|
||||
return;
|
||||
}
|
||||
|
||||
final String exportDump = GSON.toJson(activePoints);
|
||||
final String exportDump = gson.toJson(activePoints);
|
||||
|
||||
log.debug("Exported ground markers: {}", exportDump);
|
||||
|
||||
@@ -173,7 +173,7 @@ class GroundMarkerSharingManager
|
||||
try
|
||||
{
|
||||
// CHECKSTYLE:OFF
|
||||
importPoints = GSON.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||
importPoints = gson.fromJson(clipboardText, new TypeToken<List<GroundMarkerPoint>>(){}.getType());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
catch (JsonSyntaxException e)
|
||||
|
||||
@@ -88,7 +88,6 @@ public class ObjectIndicatorsPlugin extends Plugin
|
||||
private static final String MARK = "Mark object";
|
||||
private static final String UNMARK = "Unmark object";
|
||||
|
||||
private final Gson GSON = new Gson();
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private final List<ColorTileObject> objects = new ArrayList<>();
|
||||
private final Map<Integer, Set<ObjectPoint>> points = new HashMap<>();
|
||||
@@ -108,6 +107,9 @@ public class ObjectIndicatorsPlugin extends Plugin
|
||||
@Inject
|
||||
private ObjectIndicatorsConfig config;
|
||||
|
||||
@Inject
|
||||
private Gson gson;
|
||||
|
||||
@Provides
|
||||
ObjectIndicatorsConfig provideConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -428,7 +430,7 @@ public class ObjectIndicatorsPlugin extends Plugin
|
||||
}
|
||||
else
|
||||
{
|
||||
final String json = GSON.toJson(points);
|
||||
final String json = gson.toJson(points);
|
||||
configManager.setConfiguration(CONFIG_GROUP, "region_" + id, json);
|
||||
}
|
||||
}
|
||||
@@ -442,7 +444,7 @@ public class ObjectIndicatorsPlugin extends Plugin
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<ObjectPoint> points = GSON.fromJson(json, new TypeToken<Set<ObjectPoint>>()
|
||||
Set<ObjectPoint> points = gson.fromJson(json, new TypeToken<Set<ObjectPoint>>()
|
||||
{
|
||||
}.getType());
|
||||
// Prior to multiloc support the plugin would mark objects named "null", which breaks
|
||||
|
||||
@@ -88,6 +88,9 @@ public class ScreenMarkerPlugin extends Plugin
|
||||
@Inject
|
||||
private ScreenMarkerCreationOverlay overlay;
|
||||
|
||||
@Inject
|
||||
private Gson gson;
|
||||
|
||||
@Getter
|
||||
@Inject
|
||||
private ColorPickerManager colorPickerManager;
|
||||
@@ -266,7 +269,6 @@ public class ScreenMarkerPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
final Gson gson = new Gson();
|
||||
final String json = gson
|
||||
.toJson(screenMarkers.stream().map(ScreenMarkerOverlay::getMarker).collect(Collectors.toList()));
|
||||
configManager.setConfiguration(CONFIG_GROUP, CONFIG_KEY, json);
|
||||
@@ -279,7 +281,6 @@ public class ScreenMarkerPlugin extends Plugin
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
final Gson gson = new Gson();
|
||||
final List<ScreenMarker> screenMarkerData = gson.fromJson(json, new TypeToken<ArrayList<ScreenMarker>>()
|
||||
{
|
||||
}.getType());
|
||||
|
||||
@@ -53,6 +53,9 @@ public class ClockManager
|
||||
@Inject
|
||||
private Notifier notifier;
|
||||
|
||||
@Inject
|
||||
private Gson gson;
|
||||
|
||||
@Getter
|
||||
private final List<Timer> timers = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -183,7 +186,6 @@ public class ClockManager
|
||||
|
||||
if (!Strings.isNullOrEmpty(timersJson))
|
||||
{
|
||||
final Gson gson = new Gson();
|
||||
final List<Timer> timers = gson.fromJson(timersJson, new TypeToken<ArrayList<Timer>>()
|
||||
{
|
||||
}.getType());
|
||||
@@ -200,7 +202,6 @@ public class ClockManager
|
||||
|
||||
if (!Strings.isNullOrEmpty(stopwatchesJson))
|
||||
{
|
||||
final Gson gson = new Gson();
|
||||
final List<Stopwatch> stopwatches = gson.fromJson(stopwatchesJson, new TypeToken<ArrayList<Stopwatch>>()
|
||||
{
|
||||
}.getType());
|
||||
@@ -227,14 +228,12 @@ public class ClockManager
|
||||
|
||||
void saveTimers()
|
||||
{
|
||||
final Gson gson = new Gson();
|
||||
final String json = gson.toJson(timers);
|
||||
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.TIMERS, json);
|
||||
}
|
||||
|
||||
void saveStopwatches()
|
||||
{
|
||||
final Gson gson = new Gson();
|
||||
final String json = gson.toJson(stopwatches);
|
||||
configManager.setConfiguration(TimeTrackingConfig.CONFIG_GROUP, TimeTrackingConfig.STOPWATCHES, json);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ public class WikiSearchChatboxTextInput extends ChatboxTextInput
|
||||
private static final int PREDICTION_DEBOUNCE_DELAY_MS = 200;
|
||||
|
||||
private final ChatboxPanelManager chatboxPanelManager;
|
||||
private final Gson gson = new Gson();
|
||||
|
||||
private Future<?> runningRequest = null;
|
||||
private List<String> predictions = ImmutableList.of();
|
||||
@@ -78,7 +77,7 @@ public class WikiSearchChatboxTextInput extends ChatboxTextInput
|
||||
@Inject
|
||||
public WikiSearchChatboxTextInput(ChatboxPanelManager chatboxPanelManager, ClientThread clientThread,
|
||||
ScheduledExecutorService scheduledExecutorService, @Named("developerMode") final boolean developerMode,
|
||||
OkHttpClient okHttpClient)
|
||||
OkHttpClient okHttpClient, Gson gson)
|
||||
{
|
||||
super(chatboxPanelManager, clientThread);
|
||||
this.chatboxPanelManager = chatboxPanelManager;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
package net.runelite.client.util;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.gson.Gson;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
@@ -54,7 +55,6 @@ import net.runelite.api.GameState;
|
||||
import net.runelite.api.WorldType;
|
||||
import net.runelite.client.Notifier;
|
||||
import static net.runelite.client.RuneLite.SCREENSHOT_DIR;
|
||||
import net.runelite.http.api.RuneLiteAPI;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.HttpUrl;
|
||||
@@ -75,6 +75,7 @@ public class ImageCapture
|
||||
private final Client client;
|
||||
private final Notifier notifier;
|
||||
private final OkHttpClient okHttpClient;
|
||||
private final Gson gson;
|
||||
private final String imgurClientId;
|
||||
|
||||
@Inject
|
||||
@@ -82,12 +83,14 @@ public class ImageCapture
|
||||
final Client client,
|
||||
final Notifier notifier,
|
||||
final OkHttpClient okHttpClient,
|
||||
final Gson gson,
|
||||
@Named("runelite.imgur.client.id") final String imgurClientId
|
||||
)
|
||||
{
|
||||
this.client = client;
|
||||
this.notifier = notifier;
|
||||
this.okHttpClient = okHttpClient;
|
||||
this.gson = gson;
|
||||
this.imgurClientId = imgurClientId;
|
||||
}
|
||||
|
||||
@@ -204,7 +207,7 @@ public class ImageCapture
|
||||
*/
|
||||
private void uploadScreenshot(File screenshotFile, boolean notify) throws IOException
|
||||
{
|
||||
String json = RuneLiteAPI.GSON.toJson(new ImageUploadRequest(screenshotFile));
|
||||
String json = gson.toJson(new ImageUploadRequest(screenshotFile));
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(IMGUR_IMAGE_UPLOAD_URL)
|
||||
@@ -225,8 +228,8 @@ public class ImageCapture
|
||||
{
|
||||
try (InputStream in = response.body().byteStream())
|
||||
{
|
||||
ImageUploadResponse imageUploadResponse = RuneLiteAPI.GSON
|
||||
.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ImageUploadResponse.class);
|
||||
ImageUploadResponse imageUploadResponse =
|
||||
gson.fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), ImageUploadResponse.class);
|
||||
|
||||
if (imageUploadResponse.isSuccess())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user