@Test public void shouldCreateStockMovementWithLotMovementsFromJSON() throws Exception { StockMovementItemAdapter stockMovementItemAdapter = new StockMovementItemAdapter(); String json = JsonFileReader.readJson(getClass(), "StockMovementItemWithLotItems.json"); StockMovementItem stockMovementItem = stockMovementItemAdapter.deserialize(new JsonParser().parse(json), null, null); Assert.assertThat(stockMovementItem.getLotMovementItemListWrapper().size(), is(1)); Assert.assertThat(stockMovementItem.getLotMovementItemListWrapper().get(0).getMovementQuantity(), is(-5L)); Assert.assertThat(stockMovementItem.getLotMovementItemListWrapper().get(0).getStockOnHand(), is(5L)); Assert.assertThat(stockMovementItem.getLotMovementItemListWrapper().get(0).getLot().getLotNumber(), is("TEST-A")); }
@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);  }