List of usage examples for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES
FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES
To view the source code for com.google.gson FieldNamingPolicy LOWER_CASE_WITH_UNDERSCORES.
Click Source Link
From source file:com.btkelly.gnag.utils.gson.GsonConverterFactory.java
License:Apache License
public static GsonConverterFactory create() { Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); return new GsonConverterFactory(gson); }
From source file:com.caihan.scframe.utils.json.gson.GsonConvertUtils.java
License:Apache License
public static String formatJson(String json) { try {/*from ww w. ja v a2 s . c o m*/ JsonParser jp = new JsonParser(); JsonElement je = jp.parse(json); return new GsonBuilder().setPrettyPrinting() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create().toJson(je); } catch (Exception e) { return json; } }
From source file:com.caihan.scframe.utils.json.gson.GsonConvertUtils.java
License:Apache License
public static String formatJson(Object src) { try {/*from w w w .ja va2 s . co m*/ JsonParser jp = new JsonParser(); JsonElement je = jp.parse(toJson(src)); return new GsonBuilder().setPrettyPrinting() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(Date.class, new DateTypeAdapter()).create().toJson(je); } catch (Exception e) { return e.getMessage(); } }
From source file:com.example.repository_pattern_demo.di.HttpModule.java
License:Apache License
@Provides @Singleton/*from w ww . j a va2 s . c o m*/ Gson providesGson() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapterFactory(TypeAdapterFactoryImpl.create()); gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); return gsonBuilder.create(); }
From source file:com.fmf.jersey.Login.java
@GET // Path: http://localhost/<appln-folder-name>/login/dologin @Path("/dologin") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON)//from w ww . j ava2 s. c o m // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz public String doLogin(@QueryParam("email") String uname, @QueryParam("motDePasse") String pwd, @QueryParam("lieu") String lieu) { String response = ""; Personne P = null; Lieu L; Gson gson = new GsonBuilder().setPrettyPrinting().setDateFormat("MMM d, yyyy HH:mm:ss") .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); P = personneFacade.findByMailAndPass(gson.fromJson(uname, String.class), gson.fromJson(pwd, String.class)); if (P != null) { if (P.getLieu() != null) { Lieu lieuToRemove = P.getLieu(); P.setLieu(null); personneFacade.edit(P); lieuFacade.remove(lieuToRemove); } L = gson.fromJson(lieu, Lieu.class); lieuFacade.create(L); P.setLieu(L); personneFacade.edit(P); response = gson.toJson(P); } return response; }
From source file:com.fmf.jersey.MesAmis.java
@GET // Path: http://localhost/<appln-folder-name>/login/dologin @Path("/afficher") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON)/*from ww w.ja va 2s. com*/ // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz public String listeMesAmis(@QueryParam("personne") String personne) { System.out.println("hi"); String response = ""; Personne P = null; 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()); response = gson.toJson(amisFacade.findAmis(P)); return response; }
From source file:com.fmf.jersey.MesAmis.java
@GET // Path: http://localhost/<appln-folder-name>/login/dologin @Path("/afficherdemandes") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON)/* w w w .j a va2s.co m*/ // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz public String listeDemandesAmis(@QueryParam("personne") String personne) { String response = ""; Personne P = null; 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()); response = gson.toJson(demandeAjoutFacade.findDemandes(P)); return response; }
From source file:com.fmf.jersey.MesAmis.java
@GET // Path: http://localhost/<appln-folder-name>/login/dologin @Path("/delete") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON)/* ww w . ja v a 2s.co m*/ // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz public String deleteAmi(@QueryParam("personne") String personne, @QueryParam("personneasupprimer") String ASupprimer) { String response = ""; System.out.println("how you doing"); Personne P = null; Personne P2 = null; 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); P2 = gson.fromJson(ASupprimer, Personne.class); P = personneFacade.find(P.getId()); P2 = personneFacade.find(P2.getId()); System.out.println(P2.getNom()); AmisPK A = new AmisPK(); A.setPersonne(P.getId()); A.setAmi(P2.getId()); amisFacade.remove(amisFacade.find(A)); A.setPersonne(P2.getId()); A.setAmi(P.getId()); amisFacade.remove(amisFacade.find(A)); response = "deleted"; System.out.println(response); return response; }
From source file:com.fmf.jersey.MesAmis.java
@GET // Path: http://localhost/<appln-folder-name>/login/dologin @Path("/decision") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON)/*from ww w .ja v a 2s . com*/ // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz public String decideAmi(@QueryParam("personne") String personne, @QueryParam("personneasupprimer") String ASupprimer, @QueryParam("decision") String decision) { String response = ""; System.out.println("how you doing"); Personne P = null; Personne P2 = null; 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); P2 = gson.fromJson(ASupprimer, Personne.class); P = personneFacade.find(P.getId()); P2 = personneFacade.find(P2.getId()); System.out.println(decision); demandeAjoutFacade.decision(P, P2, gson.fromJson(decision, boolean.class)); response = "ok"; System.out.println(response); return response; }
From source file:com.fmf.jersey.MesAmis.java
@GET // Path: http://localhost/<appln-folder-name>/login/dologin @Path("/affichertoadd") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON)/*from w w w. j a va 2s .c o m*/ // Query parameters are parameters: http://localhost/<appln-folder-name>/login/dologin?username=abc&password=xyz public String findPeople(@QueryParam("personne") String p, @QueryParam("offset") String offset, @QueryParam("nom") String nom, @QueryParam("prenom") String prenom, @QueryParam("nbre") String nbre, @QueryParam("premierappel") String premierappel) { String response = ""; Personne P = null; System.out.println("hi you"); System.out.println("l'offset : " + offset); //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(p, Personne.class); P = personneFacade.find(P.getId()); List<Personne> le = personneFacade.search(P, gson.fromJson(offset, Integer.class), gson.fromJson(nom, String.class), gson.fromJson(prenom, String.class), gson.fromJson(nbre, Integer.class), gson.fromJson(premierappel, boolean.class)); System.out.println(le.size()); response = gson.toJson(le); // } catch (IOException ex) { // Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); // } System.out.println("bye you"); return response; }