@Test public void readObjectFieldValue() throws Exception { final ProductSkuSearchResultDTOImpl dtoSKU = new ProductSkuSearchResultDTOImpl(); dtoSKU.setAttributes(new StoredAttributesDTOImpl()); dtoSKU.setDisplayName(new StringI18NModel("EN#~#DisplayName SKU")); dtoSKU.setCode("CODE"); dtoSKU.setAvailability(2); dtoSKU.setAvailablefrom(LocalDateTime.now()); dtoSKU.setMaxOrderQuantity(BigDecimal.ONE); dtoSKU.setQtyOnWarehouse(new HashMap<Long, BigDecimal>() {{ put(123L, BigDecimal.TEN); }}); dtoSKU.getAttributes().putValue("attr1", "val1", "en#~#name1"); final ProductSearchResultDTOImpl dto = new ProductSearchResultDTOImpl(); dto.setAttributes(new StoredAttributesDTOImpl()); dto.setDisplayName(new StringI18NModel("EN#~#DisplayName")); dto.setCode("CODE"); dto.setShippable(true); dto.setConfigurable(true); dto.getAttributes().putValue("attr1", "val1", "en#~#name1"); dto.setBaseSkus(new HashMap<Long, ProductSkuSearchResultDTO>() {{ put(dtoSKU.getId(), dtoSKU); }}); final String json = AdapterUtils.writeObjectFieldValue(dto); final ProductSearchResultDTO dtoCopy = AdapterUtils.readObjectFieldValue(json, dto.getClass()); assertNotNull(dtoCopy); assertEquals("CODE", dtoCopy.getCode()); assertEquals(1, dtoCopy.getAvailability()); assertNull(dtoCopy.getAvailablefrom()); assertNull(dtoCopy.getMaxOrderQuantity()); assertNotNull(dtoCopy.getQtyOnWarehouse(123L)); assertTrue(dtoCopy.getQtyOnWarehouse(123L).isEmpty()); assertNotNull(dtoCopy.getAttributes()); assertNotNull(dtoCopy.getAttributes().getValue("attr1")); assertEquals("val1", dtoCopy.getAttributes().getValue("attr1").getFirst()); assertNotNull(dtoCopy.getAttributes().getValue("attr1").getSecond()); assertEquals("name1", dtoCopy.getAttributes().getValue("attr1").getSecond().getValue("en")); assertFalse(dtoCopy.isService()); assertTrue(dtoCopy.isShippable()); assertFalse(dtoCopy.isDigital()); assertFalse(dtoCopy.isDownloadable()); assertTrue(dtoCopy.isConfigurable()); final ProductSkuSearchResultDTO dtoSkuCopy = dtoCopy.getBaseSku(dtoSKU.getId()); assertNotNull(dtoSkuCopy); assertNotSame(dtoSKU, dtoSkuCopy); assertNotNull(dtoSkuCopy.getAvailablefrom()); assertEquals(BigDecimal.ONE, dtoSkuCopy.getMaxOrderQuantity()); assertNotNull(dtoCopy.getQtyOnWarehouse(123L)); assertNull(dtoCopy.getQtyOnWarehouse(123L).get("ABC")); dtoCopy.setSearchSkus(Collections.singletonList(dtoSkuCopy)); assertNotNull(dtoCopy.getAvailablefrom()); assertEquals(BigDecimal.ONE, dtoCopy.getMaxOrderQuantity()); assertNotNull(dtoCopy.getQtyOnWarehouse(123L)); assertEquals(BigDecimal.TEN, dtoCopy.getQtyOnWarehouse(123L).get("CODE")); }
public static <T> T readObjectFieldValue(final String serialized, final Class<T> clazz) { if (StringUtils.isNotBlank(serialized)) { try { return MAPPER.readValue(serialized, clazz); } catch (Exception exp) { LOGFTQ.error("Unable to de-serialise the object in field: " + FIELD_OBJECT + ", object: " + serialized, exp); } } return null; }
AdapterUtils { public static <T> T readObjectFieldValue(final String serialized, final Class<T> clazz) { if (StringUtils.isNotBlank(serialized)) { try { return MAPPER.readValue(serialized, clazz); } catch (Exception exp) { LOGFTQ.error("Unable to de-serialise the object in field: " + FIELD_OBJECT + ", object: " + serialized, exp); } } return null; } }
AdapterUtils { public static <T> T readObjectFieldValue(final String serialized, final Class<T> clazz) { if (StringUtils.isNotBlank(serialized)) { try { return MAPPER.readValue(serialized, clazz); } catch (Exception exp) { LOGFTQ.error("Unable to de-serialise the object in field: " + FIELD_OBJECT + ", object: " + serialized, exp); } } return null; } private  AdapterUtils(); }
AdapterUtils { public static <T> T readObjectFieldValue(final String serialized, final Class<T> clazz) { if (StringUtils.isNotBlank(serialized)) { try { return MAPPER.readValue(serialized, clazz); } catch (Exception exp) { LOGFTQ.error("Unable to de-serialise the object in field: " + FIELD_OBJECT + ", object: " + serialized, exp); } } return null; } private  AdapterUtils(); static T readObjectFieldValue(final String serialized, final Class<T> clazz); }
AdapterUtils { public static <T> T readObjectFieldValue(final String serialized, final Class<T> clazz) { if (StringUtils.isNotBlank(serialized)) { try { return MAPPER.readValue(serialized, clazz); } catch (Exception exp) { LOGFTQ.error("Unable to de-serialise the object in field: " + FIELD_OBJECT + ", object: " + serialized, exp); } } return null; } private  AdapterUtils(); static T readObjectFieldValue(final String serialized, final Class<T> clazz); static final String FIELD_PK; static final String FIELD_CLASS; static final String FIELD_OBJECT; static final String FIELD_INDEXTIME; }