SetStoragePolicyTaskParameters { public static SetStoragePolicyTaskParameters deserialize(String taskParameters) { JaxbJsonSerializer<SetStoragePolicyTaskParameters> serializer = new JaxbJsonSerializer<>(SetStoragePolicyTaskParameters.class); try { SetStoragePolicyTaskParameters params = serializer.deserialize(taskParameters); if (null == params.getSpaceId() || params.getSpaceId().isEmpty() || null == params.getStorageClass() || params.getStorageClass().isEmpty() || null == params.daysToTransition || params.daysToTransition < 0) { throw new TaskDataException( "Task parameter values may not be empty"); } return params; } catch (IOException e) { throw new TaskDataException( "Unable to parse task parameters due to: " + e.getMessage()); } } SetStoragePolicyTaskParameters(); String getSpaceId(); void setSpaceId(String spaceId); String getStorageClass(); void setStorageClass(String storageClass); Integer getDaysToTransition(); void setDaysToTransition(Integer daysToTransition); String serialize(); static SetStoragePolicyTaskParameters deserialize(String taskParameters);  }
@Test public void testDeserialize() { String taskParamsSerialized = "{\"spaceId\" : \"" + spaceId + "\"," + "\"storageClass\" : \"" + storageClass + "\"," + "\"daysToTransition\" : " + daysToTransition + "}"; SetStoragePolicyTaskParameters taskParams = SetStoragePolicyTaskParameters.deserialize(taskParamsSerialized); assertEquals(spaceId, taskParams.getSpaceId()); assertEquals(storageClass, taskParams.getStorageClass()); assertEquals(daysToTransition, taskParams.getDaysToTransition()); taskParamsSerialized = "{\"spaceId\" : \"\", " + "\"storageClass\" : \"\", " + "\"daysToTransition\" : -1}"; try { SetStoragePolicyTaskParameters.deserialize(taskParamsSerialized); fail("Exception expected: Invalid params"); } catch (TaskDataException e) { } try { SetStoragePolicyTaskParameters.deserialize(""); fail("Exception expected: Invalid params"); } catch (TaskDataException e) { } }