Example usage for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

List of usage examples for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

Introduction

In this page you can find the example usage for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.

Prototype

FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES

To view the source code for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.

Click Source Link

Document

Using this naming policy with Gson will modify the Java Field name from its camel cased form to a lower case field name where each word is separated by an underscore (_).

Usage

From source file:com.popdeem.sdk.core.deserializer.PDSocialMediaFriendsDeserializer.java

License:Open Source License

@Override
public ArrayList<PDSocialMediaFriend> deserialize(JsonElement json, Type typeOfT,
        JsonDeserializationContext context) throws JsonParseException {
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDSocialMediaFriend.class, new PDSocialMediaFriendDeserializer())
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    JsonObject jsonObject = json.getAsJsonObject();
    if (jsonObject.has("data")) {
        JsonArray array = jsonObject.getAsJsonArray("data");
        return gson.fromJson(array, typeOfT);
    }//from   w  w w  . j a v  a  2 s . c  o m
    return new ArrayList<>();
}

From source file:com.popdeem.sdk.core.deserializer.PDUserDeserializer.java

License:Open Source License

@Override
public PDUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    Gson gson = new GsonBuilder().registerTypeAdapter(long.class, new PDLongDeserializer())
            .registerTypeAdapter(int.class, new PDIntDeserializer())
            .registerTypeAdapter(PDUserFacebook.class, new PDSocialAccountFacebookDeserializer())
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    JsonElement userElement = json.getAsJsonObject().get("user");
    return gson.fromJson(userElement, PDUser.class);
}

From source file:com.popdeem.sdk.uikit.fragment.PDUIInstagramLoginFragment.java

License:Open Source License

private void authenticateInstagram(String code) {
    mProgress.setVisibility(View.VISIBLE);
    mWebView.setVisibility(View.INVISIBLE);

    PDLog.d(getClass(), "code=" + code);

    OkHttpClient httpClient = new OkHttpClient();
    FormBody.Builder bodyBuilder = new FormBody.Builder().add("client_id", mClientId)
            .add("client_secret", mClientSecret).add("grant_type", "authorization_code")
            .add("redirect_uri", mCallbackUrl).add("code", code);

    final Request request = new Request.Builder().url("https://api.instagram.com/oauth/access_token")
            .post(bodyBuilder.build()).build();

    httpClient.newCall(request).enqueue(new Callback() {
        @Override//from w  w  w .  java 2s  . co  m
        public void onFailure(Call call, final IOException e) {
            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        PDLog.e(getClass(), "error:" + e.getLocalizedMessage());
                        mCallback.error(e.getLocalizedMessage());
                        notCanceled = true;
                        removeThisFragment();
                    }
                });
            }
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            final String responseBody = response.body().string();
            PDLog.d(getClass(), "response: " + responseBody);
            if (getActivity() != null) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Gson gson = new GsonBuilder()
                                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
                        PDInstagramResponse instagramResponse = gson.fromJson(responseBody,
                                PDInstagramResponse.class);
                        notCanceled = true;
                        mCallback.loggedIn(instagramResponse);
                        removeThisFragment();
                    }
                });
            }
        }
    });
}

From source file:com.prgguru.jersey.EvenementsAmis.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/afficher")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)/*from   w  ww.j av a2  s .  c om*/
// Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz
public String afficherEvenements(@QueryParam("personne") String personne, @QueryParam("offset") String offset,
        @QueryParam("nbre") String nbre, @QueryParam("plusAncien") String plusAncien) {
    String response = "";
    Personne P = null;
    System.out.println("hi you");
    //try {
    //rcupration de la personne concerne

    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    P = gson.fromJson(personne, Personne.class);
    P = personneFacade.find(P.getId());

    List<Evenement> evenements = participationFacade.evenementsAmis(P, gson.fromJson(offset, Integer.class),
            gson.fromJson(nbre, Integer.class), gson.fromJson(plusAncien, boolean.class));

    response = gson.toJson(evenements);

    // } catch (IOException ex) {
    //    Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    // }
    System.out.println("bye you");

    return response;

}

From source file:com.prgguru.jersey.MesEvenements.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/afficher")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)// www.j av  a 2s.  c  o m
// Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz
public String afficherEvenements(@QueryParam("personne") String personne, @QueryParam("offset") String offset,
        @QueryParam("nbre") String nbre, @QueryParam("plusAncien") String plusAncien) {
    String response = "";
    Personne P = null;
    System.out.println("hi you");

    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    P = gson.fromJson(personne, Personne.class);
    P = personneFacade.find(P.getId());

    List<Evenement> evenements = participationFacade.mesEvenements(P, gson.fromJson(offset, Integer.class),
            gson.fromJson(nbre, Integer.class), gson.fromJson(plusAncien, boolean.class));
    System.out.println(evenements.size());

    response = gson.toJson(evenements);

    return response;
}

From source file:com.prgguru.jersey.MesEvenements.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/createEvent")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)/*from   w ww .ja va2  s. c  o m*/
public String creerEvenement(@QueryParam("evenement") String event) {
    Evenement a = null;
    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    a = gson.fromJson(event, Evenement.class);
    Date actuelle = new Date();
    Lieu lieu = a.getLieu();

    lieuFacade.create(lieu);

    a.setDateDeCreation(actuelle);
    a.setLieu(lieu);
    evenementFacade.create(a);
    Participation P = new Participation();
    P.setDate(actuelle);
    P.setEvenement1(a);
    Personne pers = personneFacade.find(a.getOrganisateur().getId());
    P.setPersonne(pers);
    ParticipationPK pk = new ParticipationPK();
    pk.setEvenement(a.getId());
    pk.setParticipant(pers.getId());
    P.setParticipationPK(pk);
    participationFacade.create(P);

    return ("created");
}

From source file:com.prgguru.jersey.MesEvenements.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/add")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)//from   w w  w. j a  v a2 s .  c o  m
public String participer(@QueryParam("personne") String pers, @QueryParam("evenement") String event) {
    Evenement a = null;
    Personne P = null;
    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    a = evenementFacade.find(gson.fromJson(event, Evenement.class).getId());
    P = personneFacade.find(gson.fromJson(pers, Personne.class).getId());
    Date actuelle = new Date();

    Participation Par = new Participation();
    Par.setDate(actuelle);
    Par.setEvenement1(a);

    Par.setPersonne(P);
    ParticipationPK pk = new ParticipationPK();
    pk.setEvenement(a.getId());
    pk.setParticipant(P.getId());
    Par.setParticipationPK(pk);
    participationFacade.create(Par);

    return ("added");
}

From source file:com.prgguru.jersey.MesEvenements.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/createPost")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)//w  w  w  .j av  a2s  . co  m
public String creerPost(@QueryParam("post") String event) {
    Post a = null;
    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    a = gson.fromJson(event, Post.class);
    Date actuelle = new Date();

    a.setDate(actuelle);
    postFacade.create(a);

    return ("created");
}

From source file:com.prgguru.jersey.Posts.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/afficher")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)/*  w w  w.ja  v a2s .com*/
// Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz
public String afficherPosts(@QueryParam("evenement") String evenement) {
    List<Post> listPost = new ArrayList<Post>();
    String response = "";
    Evenement ev = null;

    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    ev = gson.fromJson(evenement, Evenement.class);
    listPost.addAll(postFacade.findAllByEvenement(ev));

    response = gson.toJson(listPost);

    return response;
}

From source file:com.prgguru.jersey.ProfilGestion.java

@GET
// Path: http://localhost/<appln-folder-name>/login/dologin
@Path("/update")
// Produces JSON as response
@Produces(MediaType.APPLICATION_JSON)//w w  w  .  jav a  2 s.  c o m
// Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz
public String updateProfil(@QueryParam("personne") String personne) {
    String response = "";
    Personne P;
    Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss")
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

    P = gson.fromJson(personne, Personne.class);
    System.out.println(P.getNom() + " : " + P.getId());
    personneFacade.edit(P);
    response = "updated";
    return response;
}