Search in sources :

Example 51 with GsonBuilder

use of com.google.gson.GsonBuilder in project ranger by apache.

the class RangerAdminClientImpl method init.

public void init(String serviceName, String appId, String configPropertyPrefix) {
    Gson gson = null;
    try {
        gson = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().create();
    } catch (Throwable excp) {
        LOG.error("RangerAdminClientImpl: failed to create GsonBuilder object", excp);
    }
    this.gson = gson;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Example 52 with GsonBuilder

use of com.google.gson.GsonBuilder in project ranger by apache.

the class RangerAdminClientImpl method init.

@Override
public void init(String serviceName, String appId, String configPropertyPrefix) {
    Gson gson = null;
    try {
        gson = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().create();
    } catch (Throwable excp) {
        LOG.error("RangerAdminClientImpl: failed to create GsonBuilder object", excp);
    }
    this.gson = gson;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Example 53 with GsonBuilder

use of com.google.gson.GsonBuilder in project SecurityCraft by Geforce132.

the class VersionUpdateChecker method getNBTTagCompound.

public static NBTTagCompound getNBTTagCompound() {
    NBTTagCompound tag = new NBTTagCompound();
    Gson gson = new GsonBuilder().create();
    try {
        URL updateURL = new URL("https://www.github.com/Geforce132/SecurityCraft/raw/master/Updates/" + Loader.MC_VERSION + ".json");
        BufferedReader in = new BufferedReader(new InputStreamReader(updateURL.openStream()));
        Update update = gson.fromJson(in, Update.class);
        if (update == null)
            return null;
        if ((update.getVersion().matches("0.0.0") && update.getFileName().matches("test")) || update.getVersion().matches(SecurityCraft.getVersion())) {
            SecurityCraft.log("Running the latest version, no new updates avaliable.");
            return null;
        }
        tag.setString("newVersion", update.getVersion());
        tag.setString("updateUrl", update.getDownloadURL());
        tag.setString("changelog", update.getChangelog());
        tag.setString("newFileName", update.getFileName());
        tag.setBoolean("isDirectLink", true);
    } catch (JsonSyntaxException e) {
        e.printStackTrace();
        return null;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (MalformedURLException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return tag;
}
Also used : MalformedURLException(java.net.MalformedURLException) JsonSyntaxException(com.google.gson.JsonSyntaxException) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) IOException(java.io.IOException) URL(java.net.URL)

Example 54 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_dd_p3.

// //////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_dd_p3(final OnNetworkCallback_DD_P3 listener, int member_id, int ex31, int ex32, int ex33, int ex34, int ex35, int ex36, int ex37) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataDDP3(member_id, ex31, ex32, ex33, ex34, ex35, ex36, ex37);
    call.enqueue(new Callback<POJO_DD_P3>() {

        @Override
        public void onResponse(Call<POJO_DD_P3> call, Response<POJO_DD_P3> response) {
            try {
                POJO_DD_P3 affective3 = (POJO_DD_P3) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(affective3);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_DD_P3> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) POJO_DD_P3(com.example.user.dvectn.POJO.POJO_DD_P3) Gson(com.google.gson.Gson) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Example 55 with GsonBuilder

use of com.google.gson.GsonBuilder in project DVECTN by tanaponudom.

the class NetworkConnectionManager method callServer_dd_p2.

// /////////////////////////////////////////////////////////////////////////////////////////////////
public void callServer_dd_p2(final OnNetworkCallback_DD_P2 listener, int member_id, int ex22, int ex23, int ex24, int ex25, int ex26, int ex27, int ex28, int ex29) {
    Gson gson = new GsonBuilder().setLenient().create();
    final Retrofit retrofit = new Retrofit.Builder().baseUrl(Fragment_login.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).build();
    APISERVER callapi = retrofit.create(APISERVER.class);
    Call call = callapi.getDataDDP2(member_id, ex22, ex23, ex24, ex25, ex26, ex27, ex28, ex29);
    call.enqueue(new Callback<POJO_DD_P2>() {

        @Override
        public void onResponse(Call<POJO_DD_P2> call, Response<POJO_DD_P2> response) {
            try {
                POJO_DD_P2 affective2 = (POJO_DD_P2) response.body();
                if (response.code() != 200) {
                    // Log.e("Network connected","Response code = "+response.code());
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody != null) {
                        listener.onBodyError(responseBody);
                    } else if (responseBody == null) {
                        listener.onBodyErrorIsNull();
                    }
                // Toast.makeText(, ""+loginRes.getAccesstoken(), Toast.LENGTH_SHORT).show();
                // Log.e("Network connected","Response code = "+loginRes.getAccesstoken());
                } else {
                    listener.onResponse(affective2);
                }
            } catch (Exception e) {
            // Log.e("Network connect error",e.getMessage());
            }
        }

        @Override
        public void onFailure(Call<POJO_DD_P2> call, Throwable t) {
            Log.e("NT", t.getMessage());
            try {
                listener.onFailure(t);
            } catch (Exception e) {
                listener.onFailure(t);
            // Log.e("Network connectLogin",t.getMessage());
            }
        }
    });
}
Also used : Call(retrofit2.Call) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) POJO_DD_P2(com.example.user.dvectn.POJO.POJO_DD_P2) ResponseBody(okhttp3.ResponseBody) Retrofit(retrofit2.Retrofit)

Aggregations

GsonBuilder (com.google.gson.GsonBuilder)1067 Gson (com.google.gson.Gson)803 IOException (java.io.IOException)185 Test (org.junit.Test)141 ArrayList (java.util.ArrayList)101 JsonObject (com.google.gson.JsonObject)90 File (java.io.File)80 JsonElement (com.google.gson.JsonElement)78 HashMap (java.util.HashMap)67 List (java.util.List)62 Map (java.util.Map)59 Retrofit (retrofit2.Retrofit)56 Type (java.lang.reflect.Type)52 FileNotFoundException (java.io.FileNotFoundException)42 TypeToken (com.google.gson.reflect.TypeToken)40 ResponseBody (okhttp3.ResponseBody)39 FileOutputStream (java.io.FileOutputStream)38 Call (retrofit2.Call)38 JsonSyntaxException (com.google.gson.JsonSyntaxException)37 JsonParser (com.google.gson.JsonParser)36