forked from FabricMC/fabric-filament
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Juuxel/libraries-moshi
Switch JSON parsing to Moshi
- Loading branch information
Showing
5 changed files
with
21 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
package net.fabricmc.filament.util; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.squareup.moshi.Moshi; | ||
import okio.Okio; | ||
|
||
public class JsonUtil { | ||
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); | ||
private static final Moshi MOSHI = new Moshi.Builder().build(); | ||
|
||
public static <T> T parseFromUrl(String url, Class<T> clazz) throws IOException { | ||
try (Reader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { | ||
return GSON.fromJson(reader, clazz); | ||
try (InputStream in = new URL(url).openStream()) { | ||
return MOSHI.adapter(clazz).fromJson(Okio.buffer(Okio.source(in))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters