@Test public void shouldCreateStockMovementFromJSON() throws Exception { StockMovementItemAdapter stockMovementItemAdapter = new StockMovementItemAdapter(); String json = JsonFileReader.readJson(getClass(), "StockMovementItem.json"); StockMovementItem stockMovementItem = stockMovementItemAdapter.deserialize(new JsonParser().parse(json), null, null); assertThat(stockMovementItem).isNotNull(); assertThat(stockMovementItem.getDocumentNumber()).isEqualTo("referenceNumber3"); assertThat(stockMovementItem.getMovementQuantity()).isEqualTo(20); assertThat(stockMovementItem.getSignature()).isEqualTo("signature"); assertThat(stockMovementItem.getReason()).isEqualTo("LOANS_DEPOSIT"); String movementDateString = new SimpleDateFormat(DateUtil.DB_DATE_FORMAT).format(stockMovementItem.getMovementDate()); assertEquals("2015-10-10", movementDateString); assertThat(stockMovementItem.getMovementType()).isEqualTo(MovementReasonManager.MovementType.NEGATIVE_ADJUST); assertThat(stockMovementItem.isSynced()).isEqualTo(true); }
@Override public StockMovementItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { StockMovementItem stockMovementItem = gson.fromJson(json, StockMovementItemResponse.class).convertToStockMovementItem(); String reason = json.getAsJsonObject().get("reason").getAsString(); try { MovementReasonManager.MovementReason movementReason = MovementReasonManager.getInstance().queryByCode(reason); stockMovementItem.setMovementType(movementReason.getMovementType()); stockMovementItem.setReason(movementReason.getCode()); } catch (MovementReasonNotFoundException e) { new LMISException(e, "StockMovementItemAdapter,deserialize").reportToFabric(); e.printStackTrace(); } Date createdDate = new Date(json.getAsJsonObject().get("createdDate").getAsLong()); stockMovementItem.setCreatedTime(createdDate); stockMovementItem.setSynced(true); return stockMovementItem; }
StockMovementItemAdapter implements JsonDeserializer<StockMovementItem> { @Override public StockMovementItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { StockMovementItem stockMovementItem = gson.fromJson(json, StockMovementItemResponse.class).convertToStockMovementItem(); String reason = json.getAsJsonObject().get("reason").getAsString(); try { MovementReasonManager.MovementReason movementReason = MovementReasonManager.getInstance().queryByCode(reason); stockMovementItem.setMovementType(movementReason.getMovementType()); stockMovementItem.setReason(movementReason.getCode()); } catch (MovementReasonNotFoundException e) { new LMISException(e, "StockMovementItemAdapter,deserialize").reportToFabric(); e.printStackTrace(); } Date createdDate = new Date(json.getAsJsonObject().get("createdDate").getAsLong()); stockMovementItem.setCreatedTime(createdDate); stockMovementItem.setSynced(true); return stockMovementItem; } }
StockMovementItemAdapter implements JsonDeserializer<StockMovementItem> { @Override public StockMovementItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { StockMovementItem stockMovementItem = gson.fromJson(json, StockMovementItemResponse.class).convertToStockMovementItem(); String reason = json.getAsJsonObject().get("reason").getAsString(); try { MovementReasonManager.MovementReason movementReason = MovementReasonManager.getInstance().queryByCode(reason); stockMovementItem.setMovementType(movementReason.getMovementType()); stockMovementItem.setReason(movementReason.getCode()); } catch (MovementReasonNotFoundException e) { new LMISException(e, "StockMovementItemAdapter,deserialize").reportToFabric(); e.printStackTrace(); } Date createdDate = new Date(json.getAsJsonObject().get("createdDate").getAsLong()); stockMovementItem.setCreatedTime(createdDate); stockMovementItem.setSynced(true); return stockMovementItem; } StockMovementItemAdapter(); }
StockMovementItemAdapter implements JsonDeserializer<StockMovementItem> { @Override public StockMovementItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { StockMovementItem stockMovementItem = gson.fromJson(json, StockMovementItemResponse.class).convertToStockMovementItem(); String reason = json.getAsJsonObject().get("reason").getAsString(); try { MovementReasonManager.MovementReason movementReason = MovementReasonManager.getInstance().queryByCode(reason); stockMovementItem.setMovementType(movementReason.getMovementType()); stockMovementItem.setReason(movementReason.getCode()); } catch (MovementReasonNotFoundException e) { new LMISException(e, "StockMovementItemAdapter,deserialize").reportToFabric(); e.printStackTrace(); } Date createdDate = new Date(json.getAsJsonObject().get("createdDate").getAsLong()); stockMovementItem.setCreatedTime(createdDate); stockMovementItem.setSynced(true); return stockMovementItem; } StockMovementItemAdapter(); @Override StockMovementItem deserialize(JsonElement json, Type typeOfT,
                                         JsonDeserializationContext context); }
StockMovementItemAdapter implements JsonDeserializer<StockMovementItem> { @Override public StockMovementItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { StockMovementItem stockMovementItem = gson.fromJson(json, StockMovementItemResponse.class).convertToStockMovementItem(); String reason = json.getAsJsonObject().get("reason").getAsString(); try { MovementReasonManager.MovementReason movementReason = MovementReasonManager.getInstance().queryByCode(reason); stockMovementItem.setMovementType(movementReason.getMovementType()); stockMovementItem.setReason(movementReason.getCode()); } catch (MovementReasonNotFoundException e) { new LMISException(e, "StockMovementItemAdapter,deserialize").reportToFabric(); e.printStackTrace(); } Date createdDate = new Date(json.getAsJsonObject().get("createdDate").getAsLong()); stockMovementItem.setCreatedTime(createdDate); stockMovementItem.setSynced(true); return stockMovementItem; } StockMovementItemAdapter(); @Override StockMovementItem deserialize(JsonElement json, Type typeOfT,
                                         JsonDeserializationContext context);  }