### Question:
GraphInventoryPatchConverter { protected String marshallObjectToPatchFormat(Object obj) { Object value = obj; try { if (!(obj instanceof Map || obj instanceof String)) { value = patchProvider.getMapper().writeValueAsString(obj); } else if (obj instanceof Map) { value = standardProvider.getMapper().writeValueAsString(obj); } } catch (JsonProcessingException e) { value = "{}"; } return (String) value; }  String convertPatchFormat(Object obj); String validatePatchObject(String payload);  }### Answer:
@Test public void convertObjectToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); GenericVnf vnf = new GenericVnf(); vnf.setIpv4Loopback0Address(""); String result = validator.marshallObjectToPatchFormat(vnf); GenericVnf resultObj = mapper.readValue(result.toString(), GenericVnf.class); assertTrue("expect object to become a String to prevent double marshalling", result instanceof String); assertNull("expect null because of custom mapper", resultObj.getIpv4Loopback0Address()); }
@Test public void convertStringToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String payload = "{\"ipv4-loopback0-address\":\"\"}"; String result = validator.marshallObjectToPatchFormat(payload); assertEquals("expect no change", payload, result); }
@Test public void convertStringToPatchFormatNull_Test() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); String payload = "{\"ipv4-loopback0-address\": null}"; String result = validator.marshallObjectToPatchFormat(payload); System.out.println(result); assertEquals("expect no change", payload, result); }
@Test public void convertMapToPatchFormatTest() throws URISyntaxException, JsonParseException, JsonMappingException, IOException { GraphInventoryPatchConverter validator = new GraphInventoryPatchConverter(); HashMap<String, String> map = new HashMap<>(); map.put("ipv4-loopback0-address", ""); map.put("ipv4-loopback1-address", "192.168.1.1"); String result = validator.marshallObjectToPatchFormat(map); assertEquals("expect string", "{\"ipv4-loopback1-address\":\"192.168.1.1\"}", result); }