List of usage examples for com.google.gson Gson fromJson
@SuppressWarnings("unchecked") public <T> T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException
From source file:Api.Bit2cClient.java
public CheckoutResponse CreateCheckout(CheckoutLinkModel data) { String Url = this.Url + "Merchant/CreateCheckout"; HashMap<String, String> params = new HashMap<String, String>(); params.put("Price", String.valueOf(data.Price.toPlainString())); params.put("Description", String.valueOf(data.Description)); params.put("CoinType", String.valueOf(data.CoinType.ordinal())); params.put("ReturnURL", String.valueOf(data.ReturnURL)); params.put("CancelURL", String.valueOf(data.CancelURL)); params.put("NotifyByEmail", String.valueOf(data.NotifyByEmail)); String response = Query(params, Url); Gson gson = new Gson(); CheckoutResponse checkoutResponse = gson.fromJson(response, CheckoutResponse.class); return checkoutResponse; }
From source file:api.BookingAPI.java
@POST @ManagedAsync//from w ww . ja v a 2 s .c o m @Consumes(MediaType.APPLICATION_JSON) public void createBooking(@Suspended final AsyncResponse asyncResponse, String newBooking) { Gson gson = new Gson(); Booking booking = new Booking(gson.fromJson(newBooking, Booking.class)); bookingDAO.insertBooking(booking).thenApply(success -> { Response response; if (success) { try { response = Response.created(new URI("/api/booking/" + booking.getBookingId())).build(); } catch (URISyntaxException ex) { ex.printStackTrace(); response = Response.status(Response.Status.CREATED).build(); } } else { response = Response.serverError().build(); } return asyncResponse.resume(response); }).exceptionally(ex -> asyncResponse .resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build())); }
From source file:api.BookingAPI.java
@PUT @ManagedAsync// w w w . jav a2 s . c o m @Consumes(MediaType.APPLICATION_JSON) public void updateBooking(@Suspended final AsyncResponse asyncResponse, String updateBooking) { Gson gson = new Gson(); Booking booking = gson.fromJson(updateBooking, Booking.class); bookingDAO.updateBooking(booking).thenApply(success -> { Response response; if (success) { response = Response.status(Response.Status.NO_CONTENT).build(); } else { response = Response.serverError().build(); } return asyncResponse.resume(response); }).exceptionally(ex -> asyncResponse .resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build())); }
From source file:api.ClientAPI.java
@POST @ManagedAsync// w ww .ja v a2s .c o m @Consumes(MediaType.APPLICATION_JSON) public void createClient(@Suspended final AsyncResponse asyncResponse, String newClient) { Gson gson = new Gson(); Client client = new Client(gson.fromJson(newClient, Client.class)); clientDAO.insertClient(client).thenApply(success -> { Response response; if (success) { try { response = Response.created(new URI("/api/client/" + client.getCliendId())).build(); } catch (URISyntaxException ex) { ex.printStackTrace(); response = Response.status(Response.Status.NOT_FOUND).build(); } } else { response = Response.serverError().build(); } return asyncResponse.resume(response); }).exceptionally(ex -> asyncResponse .resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build())); }
From source file:api.ClientAPI.java
@PUT @ManagedAsync//from w ww . ja va 2 s . c o m @Consumes(MediaType.APPLICATION_JSON) public void updateClient(@Suspended final AsyncResponse asyncResponse, String updateClient) { Gson gson = new Gson(); Client client = gson.fromJson(updateClient, Client.class); clientDAO.updateClient(client).thenApply(success -> { Response response; if (success) { response = Response.status(Response.Status.NO_CONTENT).build(); } else { response = Response.status(Response.Status.NOT_FOUND).build(); } return asyncResponse.resume(response); }).exceptionally(ex -> asyncResponse .resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build())); }
From source file:api.HotelAPI.java
@POST @ManagedAsync/*from w w w.j av a2 s . c om*/ @Consumes(MediaType.APPLICATION_JSON) public void createHotel(@Suspended final AsyncResponse asyncResponse, String newHotel) { Gson gson = new Gson(); Hotel hotel = new Hotel(gson.fromJson(newHotel, Hotel.class)); hotelDAO.insertHotel(hotel).thenApply(success -> { Response response; if (success) { try { response = Response.created(new URI("/api/client/" + hotel.getHotelId())).build(); } catch (URISyntaxException ex) { ex.printStackTrace(); response = Response.status(Response.Status.NOT_FOUND).build(); } } else { response = Response.serverError().build(); } return asyncResponse.resume(response); }).exceptionally(ex -> asyncResponse .resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build())); }
From source file:api.HotelAPI.java
@PUT @ManagedAsync/*from ww w .ja v a 2 s . c om*/ @Consumes(MediaType.APPLICATION_JSON) public void updateHotel(@Suspended final AsyncResponse asyncResponse, String updateHotel) { Gson gson = new Gson(); Hotel hotel = gson.fromJson(updateHotel, Hotel.class); hotelDAO.updateHotel(hotel).thenApply(success -> { Response response; if (success) { response = Response.status(Response.Status.NO_CONTENT).build(); } else { response = Response.serverError().build(); } return asyncResponse.resume(response); }).exceptionally(ex -> asyncResponse .resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex).build())); }
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); }