public void testSimpleWithAutoSchema() throws Exception { CsvSchema schema = MAPPER.schemaFor(FiveMinuteUser.class); // NOTE: order different from above test (as per POJO def!) FiveMinuteUser user = MAPPER .reader(schema) .forType(FiveMinuteUser.class) .readValue("Joe,Josephson,MALE,true,AwE=\n"); assertEquals("Joe", user.firstName); assertEquals("Josephson", user.lastName); assertEquals(Gender.MALE, user.getGender()); assertTrue(user.isVerified()); assertArrayEquals(new byte[] {3, 1}, user.getUserImage()); }
/** Test to verify that we can mix "untyped" access as Maps with schema information... */ public void testSimpleAsMaps() throws Exception { CsvSchema schema = MAPPER.schemaFor(FiveMinuteUser.class); MappingIterator<Map<?, ?>> it = MAPPER.reader(schema).forType(Map.class).readValues("Joe,Smith,MALE,false,"); assertTrue(it.hasNext()); Map<?, ?> result = it.nextValue(); assertEquals(5, result.size()); assertEquals("Joe", result.get("firstName")); assertEquals("Smith", result.get("lastName")); assertEquals("MALE", result.get("gender")); assertEquals("false", result.get("verified")); assertEquals("", result.get("userImage")); assertFalse(it.hasNextValue()); it.close(); }