コード例 #1
0
 private void _testSimpleExplicit(ObjectReader r, boolean useBytes) throws Exception {
   r = r.forType(FiveMinuteUser.class);
   FiveMinuteUser user;
   final String INPUT = "Bob,Robertson,MALE,AQIDBAU=,false\n";
   if (useBytes) {
     user = r.readValue(INPUT);
   } else {
     user = r.readValue(INPUT.getBytes("UTF-8"));
   }
   assertEquals("Bob", user.firstName);
   assertEquals("Robertson", user.lastName);
   assertEquals(Gender.MALE, user.getGender());
   assertFalse(user.isVerified());
   assertArrayEquals(new byte[] {1, 2, 3, 4, 5}, user.getUserImage());
 }
コード例 #2
0
  public void testSimpleExplicitWithBOM() throws Exception {
    ObjectReader r = MAPPER.reader(SIMPLE_SCHEMA);
    r = r.forType(FiveMinuteUser.class);
    FiveMinuteUser user;

    ByteArrayOutputStream b = new ByteArrayOutputStream();

    // first, UTF-8 BOM:
    b.write(new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF});
    b.write("Bob,Robertson,MALE,AQIDBAU=,false\n".getBytes("UTF-8"));
    b.close();

    user = r.readValue(b.toByteArray());
    String fn = user.firstName;

    if (!fn.equals("Bob")) {
      fail("Expected 'Bob' (3), got '" + fn + "' (" + fn.length() + ")");
    }
    assertEquals("Robertson", user.lastName);
    assertEquals(Gender.MALE, user.getGender());
    assertFalse(user.isVerified());
    assertArrayEquals(new byte[] {1, 2, 3, 4, 5}, user.getUserImage());
  }