Skip to content

Commit a97f2fe

Browse files
committed
Add MiscUtility#JSON_PARSER
1 parent b45b032 commit a97f2fe

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/main/java/xyz/srnyx/javautilities/MiscUtility.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package xyz.srnyx.javautilities;
22

3+
import com.google.gson.JsonParser;
4+
35
import org.jetbrains.annotations.NotNull;
46

57
import java.util.Arrays;
@@ -20,6 +22,10 @@ public class MiscUtility {
2022
* A {@link Random} instance
2123
*/
2224
@NotNull public static final Random RANDOM = new Random();
25+
/**
26+
* A {@link JsonParser} instance
27+
*/
28+
@NotNull public static final JsonParser JSON_PARSER = new JsonParser();
2329
/**
2430
* The number of available CPU processors
2531
*/

src/main/java/xyz/srnyx/javautilities/manipulation/Mapper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.gson.JsonElement;
44
import com.google.gson.JsonNull;
5-
import com.google.gson.JsonParser;
65
import com.google.gson.JsonPrimitive;
76

87
import org.jetbrains.annotations.NotNull;
@@ -20,8 +19,6 @@
2019
* A utility class for converting {@link Object Objects} to other types
2120
*/
2221
public class Mapper {
23-
@NotNull private static final JsonParser JSON_PARSER = new JsonParser();
24-
2522
/**
2623
* Casts an {@link Object} to the specified {@link Class}
2724
*
@@ -119,7 +116,7 @@ public static <T extends Enum<T>> Optional<T> toEnum(@Nullable String name, @Not
119116
public static Optional<JsonElement> toJson(@Nullable Object object) {
120117
if (object == null) return Optional.of(JsonNull.INSTANCE);
121118
if (object instanceof JsonElement) return Optional.of((JsonElement) object);
122-
return MiscUtility.handleException(() -> JSON_PARSER.parse(object.toString()), IllegalStateException.class);
119+
return MiscUtility.handleException(() -> MiscUtility.JSON_PARSER.parse(object.toString()), IllegalStateException.class);
123120
}
124121

125122
@NotNull

0 commit comments

Comments
 (0)