I have this code:
FVDTO.setStatus("fail"); List<String[]> invalidFields = new ArrayList<String[]>(); Iterator<ConstraintViolation<HazardSubmission>> iterator = cv.iterator(); while(iterator.hasNext()) { ConstraintViolation<HazardSubmission> i = iterator.next(); String property = i.getPropertyPath().toString(); String message = i.getMessage(); invalidFields.add(new String[] { property, message }); } FVDTO.setInvalidFields(invalidFields); return new JsonResolution(FVDTO); I've taken some out to keep things DRY so I can then use it with other classes, i.e HazardSubmission is one class, and there will be others. The below code shows my attempt, obviously manually casting <HazardSubmission> here won't work it needs to be like o.getClass();
public static List<String[]> GetInvalidProperties(Set<ConstraintViolation<Object>> cv, Object o) { List<String[]> invalidFields = new ArrayList<String[]>(); Iterator<ConstraintViolation<HazardSubmission>> iterator = cv.iterator(); while(iterator.hasNext()) { ConstraintViolation<HazardSubmission> i = iterator.next(); String property = i.getPropertyPath().toString(); String message = i.getMessage(); invalidFields.add(new String[] { property, message }); } }
The second code block fails because I don't really know what I'm doing, I want to pass in the cv for param 1, with a general object type, then somehow pass in the type as a second paramter.
Could you someone please explain how to do this?
Objectin the parameter when your method is only working onHazardSubmission?