CreateSnapshotTaskParameters extends BaseDTO { public static CreateSnapshotTaskParameters deserialize(String taskParameters) { JaxbJsonSerializer<CreateSnapshotTaskParameters> serializer = new JaxbJsonSerializer<>(CreateSnapshotTaskParameters.class); try { CreateSnapshotTaskParameters params = serializer.deserialize(taskParameters); if (null == params.getSpaceId() || params.getSpaceId().isEmpty() || null == params.getUserEmail() || params.getUserEmail().isEmpty()) { throw new SnapshotDataException("Task parameter values may not be empty"); } return params; } catch (IOException e) { throw new SnapshotDataException( "Unable to parse task parameters due to: " + e.getMessage()); } } CreateSnapshotTaskParameters(); String getSpaceId(); void setSpaceId(String spaceId); String getDescription(); void setDescription(String description); String getUserEmail(); void setUserEmail(String userEmail); String serialize(); static CreateSnapshotTaskParameters deserialize(String taskParameters);  }
@Test public void testDeserialize() { String taskParamsSerialized = "{\"spaceId\" : \"test-space\"," + " \"description\" : \"test snapshot\"," + " \"userEmail\" : \"yo@myemail.com\"}"; CreateSnapshotTaskParameters taskParams = CreateSnapshotTaskParameters.deserialize(taskParamsSerialized); assertEquals("test-space", taskParams.getSpaceId()); assertEquals("test snapshot", taskParams.getDescription()); assertEquals("yo@myemail.com", taskParams.getUserEmail()); taskParamsSerialized = "{\"spaceId\" : \"\"," + " \"description\" : \"\"," + " \"userEmail\" : \"\"}"; try { CreateSnapshotTaskParameters.deserialize(taskParamsSerialized); fail("Exception expected: Invalid params"); } catch (SnapshotDataException e) { } try { CreateSnapshotTaskParameters.deserialize(""); fail("Exception expected: Invalid params"); } catch (SnapshotDataException e) { } }