Little optimization for AbstractJSONDatabaseHandler#getGson()

This commit is contained in:
Florian CUNY 2018-10-28 16:02:54 +01:00
parent 4f5009fe0e
commit 10000b71f6

View File

@ -24,6 +24,8 @@ import world.bentobox.bentobox.database.json.adapters.WorldAdapter;
*/ */
public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHandler<T> { public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
private Gson gson;
/** /**
* Constructor * Constructor
* *
@ -34,9 +36,9 @@ public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHan
*/ */
protected AbstractJSONDatabaseHandler(BentoBox plugin, Class<T> type, DatabaseConnector databaseConnector) { protected AbstractJSONDatabaseHandler(BentoBox plugin, Class<T> type, DatabaseConnector databaseConnector) {
super(plugin, type, databaseConnector); super(plugin, type, databaseConnector);
}
protected Gson getGson() { // Build the Gson
// excludeFieldsWithoutExposeAnnotation - this means that every field to be stored should use @Expose // excludeFieldsWithoutExposeAnnotation - this means that every field to be stored should use @Expose
// enableComplexMapKeySerialization - forces GSON to use TypeAdapters even for Map keys // enableComplexMapKeySerialization - forces GSON to use TypeAdapters even for Map keys
GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization(); GsonBuilder builder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization();
@ -49,6 +51,11 @@ public abstract class AbstractJSONDatabaseHandler<T> extends AbstractDatabaseHan
builder.serializeNulls(); builder.serializeNulls();
// Allow characters like < or > without escaping them // Allow characters like < or > without escaping them
builder.disableHtmlEscaping(); builder.disableHtmlEscaping();
return builder.create();
gson = builder.create();
}
protected Gson getGson() {
return gson;
} }
} }