List of usage examples for com.google.gson Gson Gson
public Gson()
From source file:backend.ws.HealthProfessionalWS.java
public HealthProfessionalWS() { gson = new Gson(); wrapperWS = WrapperWS.getWrapperWS(); }
From source file:backend.ws.PatientWS.java
public PatientWS() { gson = new Gson(); wrapperWS = WrapperWS.getWrapperWS(); }
From source file:backend.ws.SessionWS.java
public SessionWS() { gson = new Gson(); wrapperWS = WrapperWS.getWrapperWS(); }
From source file:backend.ws.SubDomainWS.java
public SubDomainWS() { gson = new Gson(); wrapperWS = WrapperWS.getWrapperWS(); }
From source file:bank.AddUpdateBankVoucher.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . ja v a 2s . c om * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String detailJson = request.getParameter("detail"); TypeToken<List<BankPaymentReceiptModel>> token = new TypeToken<List<BankPaymentReceiptModel>>() { }; List<BankPaymentReceiptModel> detail = new Gson().fromJson(detailJson, token.getType()); response.getWriter().print(saveVoucher((ArrayList<BankPaymentReceiptModel>) detail)); }
From source file:bank.OurRabbitBank.java
public static void main(String[] args) throws Exception { ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, ExchangeName.GLOBAL, RoutingKeys.OUR_JSON_BANK); System.out.println(" [*] Waiting for messages. To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); AMQP.BasicProperties properties = delivery.getProperties(); String message = new String(delivery.getBody()); Gson g = new Gson(); Message msg = g.fromJson(message, Message.class); System.out.println(" [x] Received '" + message + "'"); sendToNormalizer(msg, properties); }// w ww .j av a 2 s . c o m }
From source file:bank.OurRabbitBank.java
private static void sendToNormalizer(Message msg, AMQP.BasicProperties props) { try {// w ww . j av a 2 s .c om Gson g = new Gson(); ConnectionFactory factory = new ConnectionFactory(); factory.setHost("datdb.cphbusiness.dk"); Connection connection = factory.newConnection(); Channel channel = connection.createChannel(); //channel.exchangeDeclare(ExchangeName.OUR_JSON_BANK_RESPONSE, "direct"); int ssn = Integer.valueOf(msg.getSsn()); double interestRate = calcRate(); String bank = "OurRabbitBank"; String correlationId = props.getCorrelationId(); LoanResponse response = new LoanResponse(ssn, interestRate, bank, correlationId); String res = g.toJson(response); channel.basicPublish(ExchangeName.OUR_JSON_BANK_RESPONSE, "", props, res.getBytes()); System.out.println(" [x] Sent '" + res + "'"); channel.close(); connection.close(); } catch (Exception e) { System.out.println("Error in OutRabbitBank: " + e.getMessage()); } }
From source file:bas.animalkingdom.SpringHelper.java
public static String getParameterFromAjaxString(String ajaxString, String paramKey) throws UnsupportedEncodingException, IOException { Gson gson = new Gson(); LinkedTreeMap result = gson.fromJson(ajaxString, LinkedTreeMap.class); return (String) result.getOrDefault(paramKey, null); }
From source file:basedefense.client.version.ModificationVersionCheck.java
License:Apache License
/** * Checks the modification version./* ww w . j a v a2 s .c o m*/ * * @return The version. */ public Optional<String> check() { // We will only run this check once as this check may take a lot of time to process if (this.latestVersion != null) return this.latestVersion; InputStreamReader inputStreamReader = null; try { HttpGet getRequest = new HttpGet(API_URL + String.format(API_PATTERN, "LordAkkarin", "BaseDefense2")); HttpResponse response = this.httpClient.execute(getRequest); Preconditions.checkState(response.getStatusLine().getStatusCode() == 200, "Expected status code 200 but received %s", response.getStatusLine()); HttpEntity entity = response.getEntity(); inputStreamReader = new InputStreamReader(entity.getContent()); Gson gson = new Gson(); JsonObject object = gson.fromJson(inputStreamReader, JsonObject.class); Preconditions.checkState(object.has("tag_name"), "No valid version found."); this.latestVersion = Optional.of(object.get("tag_name").getAsString()); } catch (Exception ex) { BaseDefenseModification.getInstance().getLogger() .warn("Unable to retrieve version information: " + ex.getMessage(), ex); this.latestVersion = Optional.empty(); } finally { IOUtils.closeQuietly(inputStreamReader); } return this.latestVersion; }