Skip to content

Instantly share code, notes, and snippets.

@snicoll
Created March 28, 2015 16:20
Show Gist options
  • Save snicoll/5e90cd5197a36155a5ff to your computer and use it in GitHub Desktop.
Save snicoll/5e90cd5197a36155a5ff to your computer and use it in GitHub Desktop.
package demo;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService;
@SpringBootApplication
public class DemoApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
public void run(String... strings) throws Exception {
Collection<String> source = Arrays.asList("1", "2", "3");
ConversionService conversionService = new DefaultConversionService();
Object target = conversionService.convert(source, TypeDescriptor.forObject(source),
TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(Integer.class)));
System.out.println(target);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment