List of usage examples for com.google.gson GsonBuilder disableHtmlEscaping
public GsonBuilder disableHtmlEscaping()
From source file:agrold.webservices.GsonMessageBodyHandler.java
private Gson getGson() { if (gson == null) { final GsonBuilder gsonBuilder = new GsonBuilder(); gson = gsonBuilder.disableHtmlEscaping().setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE) .setPrettyPrinting().serializeNulls().create(); }//from www . j a v a 2 s.c o m return gson; }
From source file:apidemo.APIDemo.java
public static String ObjectToString(Object obj) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Gson gson = gsonBuilder.disableHtmlEscaping().create(); return gson.toJson(obj); }
From source file:apidemo.APIDemo.java
public static JSMessage StringToObject(String js) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Gson gson = gsonBuilder.disableHtmlEscaping().create(); return gson.fromJson(js, JSMessage.class); }
From source file:apidemo.APIMessage.java
public static JSMessageInfo StringToObject(String js) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Gson gson = gsonBuilder.disableHtmlEscaping().create(); return gson.fromJson(js, JSMessageInfo.class); }
From source file:apidemo.APIStatistical.java
public static JSRecvStatistic StringToObject(String js) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); Gson gson = gsonBuilder.disableHtmlEscaping().create(); return gson.fromJson(js, JSRecvStatistic.class); }
From source file:cc.telepath.phage.PhageGroup.java
License:GNU General Public License
/** * Announce a new AES Key on all private channels. *//*from w ww . ja va2s .c o m*/ public void newEpochAnnouncement(String newKey, PhageFCPClient pcl) throws NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, BadPaddingException, SignatureException, InvalidKeyException, IOException, FcpException, NoSuchProviderException { Crypto c = new Crypto(); Base64 base64 = new Base64(); GsonBuilder b = new GsonBuilder(); b.disableHtmlEscaping(); Gson g = b.create(); for (PhageIdentity pi : identityList) { EpochAnnouncement announcement = new EpochAnnouncement(newKey, identityList); String stringAnnouncement = g.toJson(announcement); String AESkey = c.generateAESKey(); byte[] encryptedAnnouncement = c.AESEncrypt(stringAnnouncement.getBytes(), AESkey); //EncrypotAndSign adds a colon to the string so we've been checking the wrong string //FIXME String encryptedKey = c.encryptAndSign(pi.getPubkey(), this.PrivateKey, AESkey); try { System.out.println( c.AESDecrypt(base64.decode(new String(base64.encode(encryptedAnnouncement))), AESkey)); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } System.out.println("Membership announcement on " + pcl.putData(privateChannels.get(pi.getFreenetPubkey()).replace("KSK@", ""), (encryptedKey + ":" + new String(base64.encode(encryptedAnnouncement))).getBytes(), null, null, "text/plain", false)); } }
From source file:com.anyun.sample.db.doma.entity.DefaultSerializeEntity.java
@Override public final String asJson() { GsonBuilder gb = new GsonBuilder(); gb.disableHtmlEscaping(); Gson gson = gb.create();/*from w w w. j a v a 2 s .c o m*/ return gson.toJson(this); }
From source file:com.berniesanders.fieldthebern.dagger.MainModule.java
License:Apache License
public MainModule(Context context) { this.context = context.getApplicationContext(); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.disableHtmlEscaping(); gsonBuilder.registerTypeAdapter(ApiItem.class, new CollectionDeserializer()); gsonBuilder.registerTypeAdapter(Content.class, new PageContentDeserializer()); gsonBuilder.registerTypeAdapter(CanvassData.class, new CanvassDataSerializer()); gson = gsonBuilder.create();/*w w w .j a va 2s . c o m*/ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); rxPrefs = RxSharedPreferences.create(preferences); config = new ConfigImpl(context); }
From source file:com.buildria.mocking.serializer.GsonJsonSerializer.java
License:Open Source License
@Override public byte[] serialize(@Nonnull Object obj) throws IOException { Objects.requireNonNull(obj);//from www.j a va 2 s.c o m GsonBuilder builder = new GsonBuilder(); builder.disableHtmlEscaping(); Gson gson = builder.create(); Charset charset = ctx.getCharset(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (OutputStreamWriter osw = new OutputStreamWriter(baos, charset)) { gson.toJson(obj, osw); } return baos.toByteArray(); }
From source file:com.bzcentre.dapiPush.DapiReceiver.java
License:Open Source License
@Override public Object[] invoke(Map<String, Object> request) { NginxClojureRT.log.info(TAG + " is invoked..."); String chk_token;/*from www . jav a 2s . c om*/ String user_id; String invitations; String return_code = ""; String dummy_header = "http://www.dummy.com/dummy?"; // full url for URLEncodedUtils String payload; String provider; MsgCounter msgCounter = new MsgCounter(); @SuppressWarnings("unused") Integer isModerator; String query; String dapiToken = newBzToken(service_seed); int push_status = NGX_HTTP_FORBIDDEN; GsonBuilder gBuilder = new GsonBuilder(); gBuilder.registerTypeAdapter(new TypeToken<Receipient>() { }.getType(), new ReceipientTypeAdapter()); Gson g = gBuilder.disableHtmlEscaping().serializeNulls().create(); List<String[]> undeliverables = new ArrayList<>(); Set<String> deliverables = new HashSet<>(); String msg = ""; errMsg = null; String requestMethod; // Supported request map constants can be find in the MiniConstants file requestMethod = request.get(REQUEST_METHOD).toString(); if (requestMethod.equals(GET) && request.containsKey(QUERY_STRING)) { try { msg = dummy_header + request.get(QUERY_STRING).toString(); } catch (NullPointerException e) { errMsg = "NullPointerException" + e.getMessage(); } } else if (requestMethod.equals(POST)) { if (request.containsKey(BODY)) { InputStream body = (InputStream) request.get(BODY); BufferedReader bReader = new BufferedReader(new InputStreamReader(body)); StringBuilder sbfFileContents = new StringBuilder(); //read file line by line try { while ((msg = bReader.readLine()) != null) { sbfFileContents.append(msg); } msg = dummy_header + sbfFileContents.toString(); } catch (IOException e) { errMsg = "IOException" + e.getMessage(); } catch (NullPointerException e) { errMsg = "Null Content, Error :" + e.getMessage(); } } else { errMsg = "NO BODY"; } } if (errMsg != null) { NginxClojureRT.log.info(TAG + "http parse error:" + errMsg); return new Object[] { NGX_HTTP_BAD_REQUEST, ArrayMap.create(CONTENT_TYPE, "text/plain"), //headers map "{\"method\":\"" + requestMethod + " \", \"message\":\"" + errMsg + "\"}" //response body can be string, File or Array/Collection of string or File }; } // invitations is a base64+URLencoded string try { NginxClojureRT.log.debug(TAG + "msg get from body:\n" + msg); final Map<String, Object> queryMap = convertQueryStringToMap(msg); PushNotificationResponse<SimpleApnsPushNotification> apnsProxyResponse; chk_token = queryMap.get("dapiToken").toString(); user_id = queryMap.get("user_id").toString(); invitations = queryMap.get("invitations").toString(); invitations = StringUtils.newStringUtf8(Base64.decodeBase64(invitations)); NginxClojureRT.log.debug(TAG + "after base64 decode:\n" + invitations); if (chk_token.equals(dapiToken)) { // Hoicoi Token validation List<Receipient> invitees; NginxClojureRT.log.info(TAG + "Parsing invitees from json..." + invitations); invitees = g.fromJson(invitations, new TypeToken<ArrayList<Receipient>>() { }.getType()); NginxClojureRT.log.info(TAG + "user " + user_id + " is sending " + invitees.size() + " push token(s) to user(s) " + g.toJson(invitees.get(0).getPayload().getAcme7())); // receipient={"fcm_token","apns_token","payload"} // payload class is as APNS message payload defined, FCM needs to map to it. msgCounter.countdown = invitees.size(); NginxClojureRT.log.info(TAG + "msgCounter[countdown,apns,fcm]:" + msgCounter.list()); for (Receipient receipient : invitees) { return_code = ""; payload = g.toJson(receipient.getPayload()); // isModerator= receipient.getIsMdr(); // default state sent_request, ApnsProxy will validate the result and make state update if (receipient.getApns_Token() != null && !receipient.getApns_Token().isEmpty() && payload != null) { query = "INSERT INTO `notification_push_blacklist` (`provider`,`user_id`,`to_token`) VALUES ('apns'," + receipient.getPayload().getAcme8() + ",'" + receipient.getApns_Token() + "')"; try { stmt.executeUpdate(query); } catch (SQLException e) { if (e.getErrorCode() != 1062) { // code 1062=duplicate entry NginxClojureRT.log.info(TAG + "apns query exception near line 186: " + e.getMessage() + " when\n" + query); } } provider = "apns"; switch (inBlackList(receipient.getPayload().getAcme8(), receipient.getApns_Token())) { case "sent_request": case "false": apnsProxyResponse = apnsProxy.apnsPush(receipient.getApns_Token(), payload); if (apnsProxyResponse.isAccepted()) { NginxClojureRT.log.info(TAG + "Pushing notification to user " + receipient.getPayload().getAcme8() + " through APNS."); MessageProcessor.pushBlackList(receipient.getApns_Token(), "whiteList", null); deliverables.add(receipient.getPayload().getAcme8()); push_status = (push_status == NGX_HTTP_FORBIDDEN ? NGX_HTTP_NO_CONTENT : push_status); //status 204 return_code = "apns_pushOK"; msgCounter.countdown--; msgCounter.apns++; } else { String reason = apnsProxyResponse.getRejectionReason(); Date timestamp = apnsProxyResponse.getTokenInvalidationTimestamp(); push_status = NGX_HTTP_NOT_FOUND; if (reason.equals("BadDeviceToken") || reason.equals("Unregistered")) { MessageProcessor.pushBlackList(receipient.getApns_Token(), reason, timestamp); } else { MessageProcessor.pushBlackList(receipient.getApns_Token(), "whiteList", null); } String[] undeliverable = { provider, receipient.getApns_Token(), receipient.getPayload().getAcme8() }; undeliverables.add(undeliverable); msgCounter.countdown--; } break; case "inactive": push_status = NGX_HTTP_NOT_FOUND;// status 404, to indicate that the user removes the app. return_code = "Unregistered"; String[] undeliverable = { provider, receipient.getApns_Token(), receipient.getPayload().getAcme8() }; undeliverables.add(undeliverable); msgCounter.countdown--; NginxClojureRT.log.info(TAG + "Already in blacklist:" + receipient.getApns_Token()); break; default: msgCounter.countdown--; return_code = "apns_blacklist_null_exception"; NginxClojureRT.log.info(TAG + "APNS BlackList check return null!"); break; } } if (receipient.getFcm_Token() != null && receipient.getFcm_Token().isEmpty() && payload != null) { // Timestamp timestamp = new Timestamp(System.currentTimeMillis()); query = "INSERT INTO `notification_push_blacklist` (`provider`,`user_id`,`to_token`) VALUES ('fcm'," + receipient.getPayload().getAcme8() + ",'" + receipient.getFcm_Token() + "')"; try { stmt.executeUpdate(query); } catch (SQLException e) { if (e.getClass().getName().equals("com.mysql.jdbc.CommunicationsException")) { rebuildDBConnection("stmt", query); } if (e.getErrorCode() != 1062) { // code 1062=duplicate entry NginxClojureRT.log.info(TAG + "odbc query exception near line 223 => Code:" + e.getErrorCode() + " : " + e.getMessage() + "\n" + query); } } provider = "fcm"; String responseType = inBlackList(receipient.getPayload().getAcme8(), receipient.getFcm_Token()); switch (responseType) { case "sent_request": case "false": msgCounter.countdown--; if (fcmProxy.fcmPush(receipient.getFcm_Token(), payload)) { deliverables.add(receipient.getPayload().getAcme8()); push_status = (push_status == NGX_HTTP_FORBIDDEN ? NGX_HTTP_NO_CONTENT : push_status); //status 204 return_code = "fcm_pushOK"; msgCounter.fcm++; break; } else { String response = inBlackList(receipient.getPayload().getAcme8(), receipient.getFcm_Token()); if (!response.equals("inactive")) { NginxClojureRT.log.info("TAG" + "Some thing wrong with the fcmPush. Expecting inactive but ... ->" + response); break; } else { msgCounter.countdown++; // if is inactive, continue inactive block, so add the counter back. } } case "inactive": push_status = NGX_HTTP_NOT_FOUND;// status 404, to indicate that the user removes the app. return_code = "Unregistered"; String[] undeliverable = { provider, receipient.getFcm_Token(), receipient.getPayload().getAcme8() }; undeliverables.add(undeliverable); msgCounter.countdown--; if (responseType.equals("inactive")) NginxClojureRT.log.info(TAG + "Already in blacklist:" + receipient.getFcm_Token()); break; default: msgCounter.countdown--; return_code = "fcm_blacklist_null_exception"; NginxClojureRT.log.info(TAG + "FCM BlackList nullException!"); break; } } NginxClojureRT.log.info(TAG + "msgCounter[countdown,apns,fcm]:" + msgCounter.list()); if (msgCounter.countdown == 0) { NginxClojureRT.log.info(TAG + "There are " + (msgCounter.apns + msgCounter.fcm) + " notification(s) ha(s)(ve) been successfully pushed to user(s) " + g.toJson(deliverables) + " for => " + invitees.get(0).getPayload().getAps().getAlert().getBody()); return wrapupPushResult(receipient.getPayload().getAcme8(), push_status, return_code, deliverables, msgCounter, undeliverables); } } } else { return_code = "InvalidToken"; errMsg = "HoiCoi Token is not valid<br>" + chk_token + "<br>" + dapiToken; } } catch (IllegalArgumentException | JsonParseException | IllegalStateException | NullPointerException | ClassCastException | URISyntaxException e) { return_code = e.getClass().getName(); errMsg = e.getMessage(); e.printStackTrace(); } return new Object[] { NGX_HTTP_FORBIDDEN, ArrayMap.create(CONTENT_TYPE, "text/plain"), //headers map "{\"code\":\"" + (return_code.isEmpty() ? "future_not_response" : return_code) + "\", \"message\":\"Should return from the Future response.\"}" //response body can be string, File or Array/Collection of string or File }; }