List of usage examples for com.google.gson GsonBuilder GsonBuilder
public GsonBuilder()
From source file:co.cask.tigon.internal.app.FlowSpecificationAdapter.java
License:Apache License
public static FlowSpecificationAdapter create(SchemaGenerator generator) { GsonBuilder builder = new GsonBuilder(); addTypeAdapters(builder);/* w ww . j a v a 2s. c om*/ return new FlowSpecificationAdapter(generator, builder.create()); }
From source file:co.com.rempe.impresiones.negocio.servlets.ChatServlet.java
private Respuesta insertarChat(HttpServletRequest request) throws IOException { Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create(); String json = request.getParameter("chat"); Chat chat = gson.fromJson(json, Chat.class); if (chat != null) { if (chat.getIdConversacion() < 0) { chat.setIdConversacion(System.currentTimeMillis()); }//from ww w . ja v a2s . c o m } return chatDelegado.insertarChat(chat); }
From source file:co.edu.uniandes.csw.miso4204.security.jwt.api.VerifyToken.java
public UserDTO getDataUser(String token) { try {//ww w . j a v a2 s .c o m String userToken = JsonWebToken.decode(token, "Un14nd3s2014@", true); Gson gson = new GsonBuilder().serializeNulls().create(); UserDTO res = gson.fromJson(userToken, UserDTO.class); return res; } catch (Throwable t) { t.printStackTrace(); return null; } }
From source file:co.edu.uniandes.csw.uniandes.api.JWT.VerifyToken.java
public static String getDataToken(String token) { try {/*w w w. j ava 2s . co m*/ String userToken = JsonWebToken.decode(token, "Ejemplo", true); Gson gson = new GsonBuilder().serializeNulls().create(); UserDTO res = gson.fromJson(userToken, UserDTO.class); String tenant = res.getTenant(); return tenant; } catch (Throwable t) { t.printStackTrace(); return "error getData"; } }
From source file:co.edu.uniandes.csw.uniandes.api.JWT.VerifyToken.java
public static UserDTO getDataUser(String token) { try {/* www . j a v a 2 s .c o m*/ String userToken = JsonWebToken.decode(token, "Ejemplo", true); Gson gson = new GsonBuilder().serializeNulls().create(); UserDTO res = gson.fromJson(userToken, UserDTO.class); return res; } catch (Throwable t) { t.printStackTrace(); return null; } }
From source file:co.mitro.keyczar.JsonWriter.java
License:Open Source License
public static void writeEncrypted(GenericKeyczar input, String password, Appendable output) { KeyczarSerializer serializer = new KeyczarSerializer(password); Gson gson = new GsonBuilder().registerTypeAdapter(GenericKeyczar.class, serializer).create(); gson.toJson(input, output);/*w ww .j a v a 2 s .c o m*/ }
From source file:co.phoenixlab.hearthstone.hearthcapturelib.HearthCaptureDumpReader.java
License:Open Source License
public HearthCaptureDumpReader(Path dumpFile) throws IOException { reader = Files.newBufferedReader(dumpFile, StandardCharsets.UTF_8); gson = new GsonBuilder().registerTypeAdapter(Instant.class, new InstantTypeAdapter()).create(); }
From source file:co.svbnet.tracknz.tracking.nzpost.NZPostTrackingService.java
public List<NZPostTrackedPackage> retrievePackages(List<String> codes) throws IOException { // See https://www.nzpost.co.nz/business/developer-centre/tracking-api/track-method for docs // Build and send request URL trackingUrl = createUrl(codes); String jsonString = HttpUtil.downloadString(trackingUrl); // Parse result Gson gson = new GsonBuilder().create(); HashMap<String, NZPostTrackedPackage> packages = gson.fromJson(jsonString, new TypeToken<HashMap<String, NZPostTrackedPackage>>() { }.getType());/*from w w w . j a va 2s .c o m*/ // Turn packages into list instead of dictionary returned from API call List<NZPostTrackedPackage> packageList = new ArrayList<>(); for (Map.Entry<String, NZPostTrackedPackage> package_ : packages.entrySet()) { NZPostTrackedPackage newPackage = package_.getValue(); newPackage.setTrackingCode(package_.getKey()); packageList.add(newPackage); } return packageList; }
From source file:co.vaughnvernon.actormodel.util.serializer.AbstractSerializer.java
License:Apache License
/** * Builds my Gson instance for default behavior. *///from w w w . j a va 2 s.co m private void build() { this.gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateSerializer()) .registerTypeAdapter(Date.class, new DateDeserializer()).serializeNulls().create(); }
From source file:co.vaughnvernon.actormodel.util.serializer.AbstractSerializer.java
License:Apache License
/** * Builds my Gson instance for compact serialization behavior. *//*from www.java2s . c o m*/ private void buildForCompact() { this.gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateSerializer()) .registerTypeAdapter(Date.class, new DateDeserializer()).create(); }