use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class CsvMapperOptionalTest method testMapListOptionInteger.
@Test
public void testMapListOptionInteger() throws IOException {
final CsvMapper<List<Optional<Integer>>> mapper = CsvMapperFactory.newInstance().newBuilder(new TypeReference<List<Optional<Integer>>>() {
}).addMapping("v0").addMapping("v1").mapper();
final Iterator<List<Optional<Integer>>> iterator = mapper.iterator(new StringReader("1,2\n3"));
List<Optional<Integer>> optionalList = iterator.next();
assertEquals(2, optionalList.size());
assertEquals(1, optionalList.get(0).get().intValue());
assertEquals(2, optionalList.get(1).get().intValue());
optionalList = iterator.next();
assertEquals(1, optionalList.size());
assertEquals(3, optionalList.get(0).get().intValue());
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testIssue495.
@Test
public void testIssue495() throws Exception {
TypeReference<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> typeReference = new TypeReference<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>>() {
};
ClassMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> classMeta = this.classMeta.getReflectionService().getClassMeta(typeReference.getType());
Predicate<PropertyMeta<?, ?>> propertyFilter = new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
};
PropertyFinder<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>> propertyFinder = classMeta.newPropertyFinder(propertyFilter);
PropertyMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>, Object> p1 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("variableName", 0, false, false), new Object[0]);
PropertyMeta<Tuple2<TableA, List<Tuple3<TableB, List<TableC>, List<Tuple2<TableD, List<TableE>>>>>>, Object> p2 = propertyFinder.findProperty(new DefaultPropertyNameMatcher("variableName", 0, false, false), new Object[0]);
System.out.println("p1.getPath() = " + p1.getPath());
System.out.println("p2.getPath() = " + p2.getPath());
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperBuilderTest method testConversionCharacterToJodaTime.
@Test
public void testConversionCharacterToJodaTime() {
ClassMeta<List<DateTime>> classMeta = ReflectionService.disableAsm().<List<DateTime>>getClassMeta(new TypeReference<List<DateTime>>() {
}.getType());
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyyMMdd HH:mm:ss.SSSS Z");
Mapper<Object[], List<DateTime>> mapper = new SampleMapperBuilder<List<DateTime>>(classMeta).addMapping(new SampleFieldKey("0", 0, new Class[0], String.class), dateTimeFormatter).mapper();
DateTime now = DateTime.now();
Object[] objects = new Object[] { dateTimeFormatter.print(now) };
List<DateTime> map = mapper.map(objects);
assertEquals(now, map.get(0));
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class Issue451 method testPropertyFinderAndAppendSetter.
@Test
public void testPropertyFinderAndAppendSetter() {
ClassMeta<List<Foo>> classMeta = ReflectionService.newInstance().getClassMeta(new TypeReference<List<Foo>>() {
}.getType());
PropertyFinder<List<Foo>> finder = classMeta.newPropertyFinder(new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
});
SubPropertyMeta f = (SubPropertyMeta) finder.findProperty(DefaultPropertyNameMatcher.of("b_f"), new Object[0]);
SubPropertyMeta n = (SubPropertyMeta) finder.findProperty(DefaultPropertyNameMatcher.of("b_n"), new Object[0]);
assertEquals(AppendCollectionSetter.class, n.getOwnerProperty().getSetter().getClass());
}
use of org.simpleflatmapper.util.TypeReference in project SimpleFlatMapper by arnaudroger.
the class TypeHelperTest method testToClass.
@Test
public void testToClass() {
Assert.assertEquals(Map.class, TypeHelper.toClass(new TypeReference<Map<String, String>>() {
}.getType()));
ParameterizedType type = (ParameterizedType) new TypeReference<Map<? extends Number, String>>() {
}.getType();
assertEquals(Number.class, TypeHelper.toClass(type.getActualTypeArguments()[0]));
assertEquals(Date.class, TypeHelper.toClass(MyComparable.class.getTypeParameters()[0]));
assertEquals(Date.class, TypeHelper.toClass(Date.class));
try {
TypeHelper.toClass(new Type() {
public String getTypeName() {
return null;
}
});
fail();
} catch (UnsupportedOperationException e) {
}
assertEquals(String[].class, TypeHelper.toClass(new GenericArrayType() {
@Override
public Type getGenericComponentType() {
return String.class;
}
}));
}
Aggregations