BusinessObjectDeserializer extends JsonDeserializer<BusinessObject> { @Override public BusinessObject deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException { ObjectCodec oc = parser.getCodec(); ObjectNode treeNode = oc.readTree(parser); BusinessObject businessObject = new BusinessObject(); NodeBusinessObjectInput node = new NodeBusinessObjectInput(getValueIfExist(treeNode, NAME)); node.setMultiple(true); node.setPageDataName(getValueIfExist(treeNode, VARIABLE_NAME)); parseNodeContractInput(childInput(treeNode), node); businessObject.addInput(node); return businessObject; }  @Override BusinessObject deserialize(JsonParser parser, DeserializationContext ctxt); @Override Class<?> handledType();  }
@Test public void deserialize_a_json_complex_businessObject_into_a_businessObject_object() throws Exception { String jsonValue = "{ \"name\": \"com.company.bpm.model.Order\", \"attributes\": [ { \"name\": \"requester\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"creationDate\", \"type\": \"OFFSETDATETIME\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"modifyBy\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"modificationDate\", \"type\": \"OFFSETDATETIME\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"category\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"projectName\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"projectDescription\", \"type\": \"TEXT\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"launchDate\", \"type\": \"LOCALDATE\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"projectCode\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"process\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"comments\", \"type\": \"AGGREGATION\", \"nullable\": \"true\", \"collection\": \"true\", \"description\": \"\", \"reference\": \"com.danone.bpm.model.line\", \"fetchType\": \"LAZY\", \"attributes\": [ { \"name\": \"productName\", \"type\": \"STRING\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"creationDate\", \"type\": \"OFFSETDATETIME\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"comment\", \"type\": \"TEXT\", \"nullable\": \"true\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"quantity\", \"type\": \"INTEGER\", \"nullable\": \"false\", \"collection\": \"false\", \"description\": \"\" }, { \"name\": \"price\", \"type\": \"double\", \"nullable\": \"false\", \"collection\": \"false\", \"description\": \"\" } ] } ], \"variableName\": \"order\"}"; BusinessObject bo = deserializer.deserialize(new JsonFactory(new ObjectMapper()).createParser(jsonValue), null); NodeBusinessObjectInput rootNode = (NodeBusinessObjectInput) bo.getInput().get(0); Assert.assertEquals("order", rootNode.getPageDataName()); Assert.assertEquals(11, rootNode.getInput().size()); Assert.assertEquals(true, rootNode.getInput().get(10) instanceof NodeBusinessObjectInput); NodeBusinessObjectInput nestedBusinessObject = (NodeBusinessObjectInput) rootNode.getInput().get(10); Assert.assertEquals("order_comments", nestedBusinessObject.getPageDataName()); Assert.assertEquals("comments", nestedBusinessObject.getBusinessObjectAttributeName()); Assert.assertEquals("comments", nestedBusinessObject.getDataReference().getName()); Assert.assertEquals(BusinessDataReference.RelationType.AGGREGATION, nestedBusinessObject.getDataReference().getRelationType()); Assert.assertEquals(BusinessDataReference.LoadingType.LAZY, nestedBusinessObject.getDataReference().getLoadingType()); Assert.assertEquals(rootNode,nestedBusinessObject.getParent()); }