@Test public void testConvert() { List<Tag> expected1 = new ArrayList<>(); expected1.add(new Tag("tag1")); expected1.add(new Tag("tag2")); expected1.add(new Tag("tag3")); assertEquals(expected1, new StringArrayToListOfTagsConverter().convert(new String[] {"tag1,tag2,tag3"}, null, null)); List<Tag> expected2 = new ArrayList<>(); expected2.add(new Tag("tag1")); assertEquals(expected2, new StringArrayToListOfTagsConverter().convert(new String[] {"tag1"}, null, null)); }
@Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { String [] sourceStr = (String[])source; if(sourceStr != null && sourceStr.length > 0) { List<Tag> tags = new ArrayList<>(); String csv = sourceStr[0]; if(log.isDebugEnabled()) { log.debug("Source string: " + csv); } String [] csvList = csv.split(","); for(String str : csvList) { if(!StringUtil.isEmpty(str)) { if(log.isDebugEnabled()) { log.debug("Converting string " + str + " to Tag object"); } tags.add(new Tag(str)); } } return tags; } return null; }
StringArrayToListOfTagsConverter implements ConditionalGenericConverter { @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { String [] sourceStr = (String[])source; if(sourceStr != null && sourceStr.length > 0) { List<Tag> tags = new ArrayList<>(); String csv = sourceStr[0]; if(log.isDebugEnabled()) { log.debug("Source string: " + csv); } String [] csvList = csv.split(","); for(String str : csvList) { if(!StringUtil.isEmpty(str)) { if(log.isDebugEnabled()) { log.debug("Converting string " + str + " to Tag object"); } tags.add(new Tag(str)); } } return tags; } return null; } }
StringArrayToListOfTagsConverter implements ConditionalGenericConverter { @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { String [] sourceStr = (String[])source; if(sourceStr != null && sourceStr.length > 0) { List<Tag> tags = new ArrayList<>(); String csv = sourceStr[0]; if(log.isDebugEnabled()) { log.debug("Source string: " + csv); } String [] csvList = csv.split(","); for(String str : csvList) { if(!StringUtil.isEmpty(str)) { if(log.isDebugEnabled()) { log.debug("Converting string " + str + " to Tag object"); } tags.add(new Tag(str)); } } return tags; } return null; }  }
StringArrayToListOfTagsConverter implements ConditionalGenericConverter { @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { String [] sourceStr = (String[])source; if(sourceStr != null && sourceStr.length > 0) { List<Tag> tags = new ArrayList<>(); String csv = sourceStr[0]; if(log.isDebugEnabled()) { log.debug("Source string: " + csv); } String [] csvList = csv.split(","); for(String str : csvList) { if(!StringUtil.isEmpty(str)) { if(log.isDebugEnabled()) { log.debug("Converting string " + str + " to Tag object"); } tags.add(new Tag(str)); } } return tags; } return null; }  @Override Set<ConvertiblePair> getConvertibleTypes(); @Override Object convert(Object source, TypeDescriptor sourceType,
			TypeDescriptor targetType); @Override boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType); }
StringArrayToListOfTagsConverter implements ConditionalGenericConverter { @Override public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { String [] sourceStr = (String[])source; if(sourceStr != null && sourceStr.length > 0) { List<Tag> tags = new ArrayList<>(); String csv = sourceStr[0]; if(log.isDebugEnabled()) { log.debug("Source string: " + csv); } String [] csvList = csv.split(","); for(String str : csvList) { if(!StringUtil.isEmpty(str)) { if(log.isDebugEnabled()) { log.debug("Converting string " + str + " to Tag object"); } tags.add(new Tag(str)); } } return tags; } return null; }  @Override Set<ConvertiblePair> getConvertibleTypes(); @Override Object convert(Object source, TypeDescriptor sourceType,
			TypeDescriptor targetType); @Override boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType);  }