Skip to content

Instantly share code, notes, and snippets.

@dannyduc
Created November 5, 2013 00:53
Show Gist options
  • Save dannyduc/7312036 to your computer and use it in GitHub Desktop.
Save dannyduc/7312036 to your computer and use it in GitHub Desktop.
public class IntegrationTestUtil {
public static void addParameters(Object formObject, MockHttpServletRequest request) {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
Map<String, Object> propertyValues = mapper.convertValue(formObject, Map.class);
Set<String> propertyNames = propertyValues.keySet();
Iterator<String> nameIter = propertyNames.iterator();
for (int index=0; index < propertyNames.size(); index++) {
String currentKey = nameIter.next();
Object currentValue = propertyValues.get(currentKey);
request.setParameter(currentKey, currentValue.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment