List of usage examples for com.google.gson GsonBuilder GsonBuilder
public GsonBuilder()
From source file:br.com.bean.RestControllers.faculdadeController.java
@RequestMapping(value = "busca-faculdade-email-senha", method = RequestMethod.GET) @ResponseBody/* w w w .j av a2 s . c o m*/ public static String buscaFaculdade(@RequestParam String email, @RequestParam String senha) throws ParseException { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try { Criteria query = sessao.createCriteria(Faculdade.class).add(Restrictions.eq("email", email)) .add(Restrictions.eq("senha", senha)).add(Restrictions.eq("ativo", 1)); Faculdade f = (Faculdade) query.uniqueResult(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); f.setTurmas(null); return gson.toJson(f, Faculdade.class); } catch (HibernateException e) { transacao.rollback(); return null; } }
From source file:br.com.bean.RestControllers.festaController.java
@RequestMapping(value = "busca-festas", method = RequestMethod.GET) public String get() { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try {// w ww.j av a 2 s . co m Criteria query = sessao.createCriteria(Festa.class); Criterion ativo = Restrictions.eq("ativo", 1); query.add(ativo); List<Festa> listaDeFestas = query.list(); Type TipolistaDeFestas = new TypeToken<List<Festa>>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); return gson.toJson(listaDeFestas, TipolistaDeFestas); } catch (HibernateException e) { transacao.rollback(); return CriadorJson.criaJsonErro(e, null); } finally { sessao.close(); } }
From source file:br.com.bean.RestControllers.representanteController.java
@RequestMapping(value = "busca-representantes", method = RequestMethod.GET) public String get() throws ParseException { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try {//from ww w.ja v a2 s .c o m Criteria query = sessao.createCriteria(Representante.class); Criterion ativo = Restrictions.eq("ativo", 1); query.add(ativo); List<Representante> listaDeRepresentantes = query.list(); Type TipolistaDeRepresentantes = new TypeToken<List<Representante>>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); return gson.toJson(listaDeRepresentantes, TipolistaDeRepresentantes); } catch (HibernateException e) { transacao.rollback(); return null; } }
From source file:br.com.bean.RestControllers.turmaController.java
@RequestMapping(value = "busca-turmas", method = RequestMethod.GET) @ResponseBody//w w w. j av a 2s. c om public String buscaTurmas(long faculdadeId) throws ParseException { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try { Criteria turmaCrit = sessao.createCriteria(Turma.class); turmaCrit.add(Restrictions.eq("ativo", 1)); Criteria faculdadeCrit = turmaCrit.createCriteria("faculdade"); faculdadeCrit.add(Restrictions.eq("faculdadeId", faculdadeId)); turmaCrit.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<Turma> listaDeTurmas = turmaCrit.list(); for (Turma t : listaDeTurmas) { t.setFaculdade(null); } Type TipolistaDeTurmas = new TypeToken<List<Turma>>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); return gson.toJson(listaDeTurmas, TipolistaDeTurmas); } catch (HibernateException e) { transacao.rollback(); return null; } finally { sessao.close(); } }
From source file:br.com.bean.RestControllers.usuarioController.java
@RequestMapping(value = "busca-usuarios", method = RequestMethod.GET) @ResponseBody// w ww . j av a 2 s . co m public String get() { Session sessao = HibernateUtility.getSession(); try { Criteria query = sessao.createCriteria(Usuario.class); Criterion ativo = Restrictions.eq("ativo", 1); query.add(ativo); List<Usuario> listaDeUsuarios = query.list(); Type TipolistaDeUsuarios = new TypeToken<List<Usuario>>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); return gson.toJson(listaDeUsuarios, TipolistaDeUsuarios); } catch (HibernateException e) { return CriadorJson.criaJsonErro(e, "Verificar"); } finally { sessao.close(); } }
From source file:br.com.bean.RestControllers.vendaController.java
@RequestMapping(value = "busca-vendas", method = RequestMethod.GET) public String get() throws ParseException { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try {//w w w. ja v a2 s .co m Criteria query = sessao.createCriteria(Venda.class); Criterion ativo = Restrictions.eq("ativo", 1); query.add(ativo); List<Venda> listaDeVendas = query.list(); Type TipolistaDeVendas = new TypeToken<List<Venda>>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); return gson.toJson(listaDeVendas, TipolistaDeVendas); } catch (HibernateException e) { transacao.rollback(); return null; } }
From source file:br.com.bean.RestControllers.viagemController.java
@RequestMapping(value = "busca-viagens", method = RequestMethod.GET) public String get() throws ParseException { Session sessao = HibernateUtility.getSession(); Transaction transacao = sessao.beginTransaction(); try {/*from w w w.j av a 2 s. c om*/ Criteria query = sessao.createCriteria(Viagem.class); Criterion ativo = Restrictions.eq("ativo", 1); query.add(ativo); List<Viagem> listaDeViagens = query.list(); Type TipolistaDeViagens = new TypeToken<List<Viagem>>() { }.getType(); Gson gson = new GsonBuilder().registerTypeAdapter(Collection.class, new CollectionDeserializer()) .create(); return gson.toJson(listaDeViagens, TipolistaDeViagens); } catch (HibernateException e) { transacao.rollback(); } finally { sessao.close(); } return null; }
From source file:br.com.bean.Utilitarios.GsonHttpMessageConverter.java
License:Apache License
/** * Construct a new {@code GsonHttpMessageConverter}. * /* w w w . ja v a 2 s. com*/ * @param serializeNulls true to generate json for null values */ public GsonHttpMessageConverter(boolean serializeNulls) { this(serializeNulls ? new GsonBuilder().serializeNulls().create() : new Gson()); }
From source file:br.com.davimonteiro.lotus_runtime.config.ConfigurationUtil.java
License:Open Source License
public static Configuration load(Path configPath) { Configuration config = null;/* w ww . j a v a 2s . c om*/ GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); try { config = gson.fromJson(new FileReader(configPath.toFile()), Configuration.class); } catch (JsonSyntaxException | JsonIOException | FileNotFoundException e) { e.printStackTrace(); } return config; }
From source file:br.com.davimonteiro.lotus_runtime.config.ConfigurationUtil.java
License:Open Source License
public static Configuration load(String jsonConfig) { Configuration config = null;/*from w w w . j a va 2 s.c om*/ GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); config = gson.fromJson(jsonConfig, Configuration.class); return config; }