Skip to content

Instantly share code, notes, and snippets.

@Unh0lyTigg
Created January 12, 2015 05:23
Show Gist options
  • Save Unh0lyTigg/2b51aa2ef4c302fe40d7 to your computer and use it in GitHub Desktop.
Save Unh0lyTigg/2b51aa2ef4c302fe40d7 to your computer and use it in GitHub Desktop.
import java.lang.reflect.Type;
import net.minecraft.nbt.JsonToNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
public class Nson {
private final GsonBuilder builder = new GsonBuilder();
private Gson gson = new Gson();
public Nson() { }
public NBTBase toNBT(Object obj) throws NBTException {
return JsonToNBT.func_180713_a(gson.toJson(obj));
}
public <T> void registerTypeAdapter(Type type, TypeAdapter<T> adapter) {
builder.registerTypeAdapter(type, adapter);
gson = builder.create();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment