List of usage examples for com.google.gson GsonBuilder GsonBuilder
public GsonBuilder()
From source file:capaServicio.Servicios.java
/** * entrega una lista con las actividades de un grupo * /* w ww .j a v a 2 s. co m*/ * Web service operation * @param uidGrupo uid del grupo que contiene las actividades * @return lista tipo Json con las actividades del grupo * @throws org.orm.PersistentException */ @WebMethod(operationName = "getActividadDeGrupo") public String getActividadDeGrupo(@WebParam(name = "uidGrupo") int uidGrupo) throws PersistentException { Grupo grupo = new Grupo(); grupo.setUid(uidGrupo); List<Actividad> lista = grupo.getActividad(grupo); String listaRetorno = ""; Gson gson = new GsonBuilder().create(); listaRetorno = gson.toJson(lista); return listaRetorno; }
From source file:capaServicio.Servicios.java
/** * entrega una lista de notificaciones de un grupo * // w ww .ja v a 2 s . c o m * Web service operation * @param uidGrupo uid del grupo que contiene las notificaciones * @return lista tipo Json con las notificaciones del grupo * @throws org.orm.PersistentException */ @WebMethod(operationName = "getNotificacionGrupoServicioWeb") public String getNotificacionGrupoServicioWeb(@WebParam(name = "uidGrupo") int uidGrupo) throws PersistentException { Grupo grupo = new Grupo(); grupo.setUid(uidGrupo); List<Notificacion> lista = grupo.getNotificacion(grupo); String listaRetorno = ""; Gson gson = new GsonBuilder().create(); listaRetorno = gson.toJson(lista); return listaRetorno; }
From source file:capaServicio.Servicios.java
/** * entrega una lista con los contactos que vieron una actividad * // w w w.j a va 2 s . c o m * Web service operation * @param uidActividad uid de la actividad * @return lista tipo Json con los contactos */ @WebMethod(operationName = "getActividadVisto") public String getActividadVisto(@WebParam(name = "uidActividad") int uidActividad) { capaNegocio.Actividad actividad = new capaNegocio.Actividad(); actividad.setUid(uidActividad); List<capaNegocio.Contacto> lista = actividad.getVisto(actividad); String listaRetorno = ""; Gson gson = new GsonBuilder().create(); listaRetorno = gson.toJson(lista); return listaRetorno; }
From source file:capaServicio.Servicios.java
/** * entrega una lista con los contactos que vieron una notificacion * /* w w w . j a v a 2 s .c om*/ * Web service operation * @param uidNotificacion uid de la notificacion * @return lista tipo Json con los contactos */ @WebMethod(operationName = "getVistoNotificacion") public String getVistoNotificacion(@WebParam(name = "uidNotificacion") int uidNotificacion) { capaNegocio.Notificacion noti = new capaNegocio.Notificacion(); noti.setUid(uidNotificacion); List<capaNegocio.Contacto> lista = noti.vistoNotificacion(noti); String listaRetorno = ""; Gson gson = new GsonBuilder().create(); listaRetorno = gson.toJson(lista); return listaRetorno; }
From source file:capstoneproject.CapstoneProject.java
private static String doSearch(String query) throws MalformedURLException, IOException { String res = ""; String village = ""; PrintWriter writer = null;/* w ww. j av a 2s . c o m*/ String hasil = makeSearchString(query.replaceAll(" ", "+") + "+jakarta", 1, 10); String result = read(hasil); if (result != null) { writer = new PrintWriter(new File("hasil.txt")); writer.write(result); writer.close(); BufferedReader reader = new BufferedReader(new FileReader("hasil.txt")); Gson gson = new GsonBuilder().create(); Result ex = gson.fromJson(reader, Result.class); List<Item> items = ex.getItems(); for (int i = 0; i < items.size(); i++) { Item data = items.get(i); res = data.getLink(); break; } res = res.replaceAll("http://kodepos.whoip.org/", ""); for (Village data : records) { if (data.postal_code.equalsIgnoreCase(res)) { village = data.village; break; } } if (village != "") { route_village.put(query, village); } } return village; }
From source file:cc.agentx.client.Configuration.java
License:Apache License
@SuppressWarnings("Duplicates") private static void load() throws Exception { String json = ""; InputStream inputStream = null; for (String path : CONFIG_FILE_PATH) { inputStream = Configuration.class.getResourceAsStream(path); if (inputStream != null) { log.info("\tFound resource [{}]", path); break; }/*from ww w. jav a 2s. c o m*/ log.debug("\tCould NOT find resource [{}]", path); } for (String path : CONFIG_FILE_PATH) { File file = new File(BASE_PATH, path); if (file.exists()) { inputStream = new FileInputStream(file); log.info("\tFound resource [{}]", file.getAbsolutePath()); break; } log.debug("\tCould NOT find resource [{}]", file.getAbsolutePath()); } Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create(); if (inputStream == null) { log.warn("\tCould NOT find resource [{}]", "config.json"); File configFile = new File(BASE_PATH, "config.json"); if (configFile.createNewFile()) { log.warn("\tCreate default [config.json] at [{}]", configFile.getPath()); BufferedWriter writer = new BufferedWriter(new FileWriter(configFile)); writer.write(json = gson.toJson(new Configuration())); writer.close(); log.warn("\tPlease reboot this program after configuration."); System.exit(0); } else { throw new RuntimeException("file not found (" + configFile.getPath() + ")"); } } else { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); while (reader.ready()) { json += reader.readLine().concat("\n"); } reader.close(); } Configuration.INSTANCE = gson.fromJson(json, Configuration.class); log.debug(INSTANCE.toString()); }
From source file:cc.alessandro.jpocket.gson.GsonFactory.java
License:Open Source License
public static <T> T parser(String json, Class<T> type) { Gson gson = new GsonBuilder().registerTypeAdapter(AccessToken.class, new AccessTokenDeserializer()) .registerTypeAdapter(Statuses.class, new StatusesDeserializer()) .registerTypeAdapter(Status.class, new StatusDeserializer()).create(); return gson.fromJson(json, type); }
From source file:cc.kave.commons.utils.json.JsonUtils.java
License:Apache License
private static GsonBuilder createBuilder() { GsonBuilder gb = new GsonBuilder(); // add support for new Java 8 date/time framework gb.registerTypeHierarchyAdapter(LocalDateTime.class, new LocalDateTimeConverter()); Converters.registerAll(gb);// w ww . ja v a 2 s .c om gb.registerTypeAdapter(Duration.class, new DurationConverter()); GsonUtil.addTypeAdapters(gb); registerNames(gb); registerSSTHierarchy(gb); registerEventHierarchy(gb); gb.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE); gb.excludeFieldsWithModifiers(java.lang.reflect.Modifier.TRANSIENT); return gb; }
From source file:cc.kave.commons.utils.json.legacy.GsonUtil.java
License:Open Source License
public static synchronized Gson getInstance() { if (gson == null) { final GsonBuilder builder = new GsonBuilder(); addTypeAdapters(builder);/*from w ww. j a v a2 s . co m*/ builder.enableComplexMapKeySerialization(); gson = builder.create(); } return gson; }
From source file:cc.recommenders.utils.gson.GsonUtil.java
License:Open Source License
public static synchronized Gson getInstance() { if (gson == null) { final GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(VmMethodName.class, new GsonNameSerializer()); builder.registerTypeAdapter(IMethodName.class, new GsonNameSerializer()); builder.registerTypeAdapter(VmMethodName.class, new GsonMethodNameDeserializer()); builder.registerTypeAdapter(IMethodName.class, new GsonMethodNameDeserializer()); builder.registerTypeAdapter(VmTypeName.class, new GsonNameSerializer()); builder.registerTypeAdapter(ITypeName.class, new GsonNameSerializer()); builder.registerTypeAdapter(VmTypeName.class, new GsonTypeNameDeserializer()); builder.registerTypeAdapter(ITypeName.class, new GsonTypeNameDeserializer()); builder.registerTypeAdapter(VmFieldName.class, new GsonNameSerializer()); builder.registerTypeAdapter(IFieldName.class, new GsonNameSerializer()); builder.registerTypeAdapter(VmFieldName.class, new GsonFieldNameDeserializer()); builder.registerTypeAdapter(IFieldName.class, new GsonFieldNameDeserializer()); ///*from w w w .ja v a 2 s .co m*/ builder.registerTypeAdapter(File.class, new GsonFileDeserializer()); builder.registerTypeAdapter(File.class, new GsonFileSerializer()); // builder.setPrettyPrinting(); // builder.setDateFormat("dd.MM.yyyy HH:mm:ss"); builder.registerTypeAdapter(Date.class, new ISO8601DateParser()); builder.registerTypeAdapter(Multimap.class, new MultimapTypeAdapter()); // builder.registerTypeAdapter(Usage.class, new UsageTypeAdapter()); builder.registerTypeAdapter(Query.class, new UsageTypeAdapter()); RuntimeTypeAdapterFactory<UsageFeature> rtaf = RuntimeTypeAdapterFactory.of(UsageFeature.class, "$type") .registerSubtype(CallFeature.class).registerSubtype(ClassFeature.class) .registerSubtype(DefinitionFeature.class).registerSubtype(FirstMethodFeature.class) .registerSubtype(ParameterFeature.class).registerSubtype(SuperMethodFeature.class) .registerSubtype(TypeFeature.class); builder.registerTypeAdapterFactory(rtaf); builder.registerTypeAdapter(CallFeature.class, new ObjectUsageFeatureRedirector<CallFeature>()); builder.registerTypeAdapter(ClassFeature.class, new ObjectUsageFeatureRedirector<ClassFeature>()); builder.registerTypeAdapter(DefinitionFeature.class, new ObjectUsageFeatureRedirector<DefinitionFeature>()); builder.registerTypeAdapter(FirstMethodFeature.class, new ObjectUsageFeatureRedirector<FirstMethodFeature>()); builder.registerTypeAdapter(ParameterFeature.class, new ObjectUsageFeatureRedirector<ParameterFeature>()); builder.registerTypeAdapter(SuperMethodFeature.class, new ObjectUsageFeatureRedirector<SuperMethodFeature>()); builder.registerTypeAdapter(TypeFeature.class, new ObjectUsageFeatureRedirector<TypeFeature>()); builder.enableComplexMapKeySerialization(); gson = builder.create(); } return gson; }