Пример #1
0
 @Override
 public JsonElement serialize(
     Transaction transaction, Type type, JsonSerializationContext jsonSerializationContext) {
   final JsonObject jo = new JsonObject();
   jo.addProperty("amount", transaction.getAmount());
   jo.addProperty("type", transaction.getType());
   if (transaction.getParent() != null) {
     jo.addProperty("parent", transaction.getParent().getId());
   }
   return jo;
 }
Пример #2
0
 @RequestMapping(value = "/transactionservice/transaction/{id}", method = RequestMethod.PUT)
 public ResponseEntity addTransaction(@PathVariable("id") Long id, @RequestBody String body) {
   Transaction aTransaction = gson.fromJson(body, Transaction.class);
   aTransaction.setId(id);
   long result = transactionService.addTransaction(aTransaction);
   if (result >= 0) {
     return new ResponseEntity<String>("{ \"status\": \"ok\" }", HttpStatus.OK);
   } else {
     return new ResponseEntity<String>(
         "Oops! You tried to feed me a duplicate transaction_id. Updating is not implemented, yet.",
         HttpStatus.UNPROCESSABLE_ENTITY);
   }
 }