File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
json-data-utils/src/main/java/net/minecraftforge/util/data/json Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 88import com .google .gson .GsonBuilder ;
99import com .google .gson .JsonIOException ;
1010import com .google .gson .JsonSyntaxException ;
11+ import com .google .gson .ToNumberPolicy ;
1112import com .google .gson .reflect .TypeToken ;
13+ import com .google .gson .stream .JsonReader ;
1214
1315import java .io .ByteArrayInputStream ;
1416import java .io .File ;
2123// TODO [MCMaven][Documentation] Document
2224public class JsonData {
2325 private static final Gson GSON = new GsonBuilder ()
26+ .setObjectToNumberStrategy (JsonData ::readNumber )
2427 .setPrettyPrinting ()
2528 .create ();
2629
30+ private static Number readNumber (JsonReader in ) throws IOException {
31+ try {
32+ return ToNumberPolicy .LONG_OR_DOUBLE .readNumber (in );
33+ } catch (Throwable suppressed ) {
34+ try {
35+ return ToNumberPolicy .BIG_DECIMAL .readNumber (in );
36+ } catch (Throwable e ) {
37+ IOException throwing = new IOException ("Failed to read number from " + in , e );
38+ throwing .addSuppressed (suppressed );
39+ throw throwing ;
40+ }
41+ }
42+ }
43+
2744 public static AssetsIndex assetsIndex (File file ) {
2845 return fromJson (file , AssetsIndex .class );
2946 }
You can’t perform that action at this time.
0 commit comments