public void testCatchAndRethrow() throws Exception {
  ObjectMapper mapper=new ObjectMapper();
  CustomSerializerFactory sf=new CustomSerializerFactory();
  sf.addSpecificMapping(Bean.class,new SerializerWithErrors());
  mapper.setSerializerFactory(sf);
  try {
    StringWriter sw=new StringWriter();
    Bean[] b={new Bean()};
    List<Bean[]> l=new ArrayList<Bean[]>();
    l.add(b);
    mapper.writeValue(sw,l);
    fail("Should have gotten an exception");
  }
 catch (  IOException e) {
    verifyException(e,"test string");
    Throwable root=e.getCause();
    assertNotNull(root);
    if (!(root instanceof IllegalArgumentException)) {
      fail("Wrapped exception not IAE, but " + root.getClass());
    }
  }
}

public void testCatchAndRethrow ( ) throws Exception { ObjectMapper mapper = new ObjectMapper ( ) ; CustomSerializerFactory sf = new CustomSerializerFactory ( ) ; sf . addSpecificMapping ( Bean . class , new SerializerWithErrors ( ) ) ; mapper . setSerializerFactory ( sf ) ; try { StringWriter sw = new StringWriter ( ) ; Bean [ ] b = { new Bean ( ) } ; List < Bean [ ] > l = new ArrayList < Bean [ ] > ( ) ; l . add ( b ) ; mapper . writeValue ( sw , l ) ; fail ( "Should have gotten an exception" ) ; } catch ( IOException e ) { verifyException ( e , "test string" ) ; Throwable root = e . getCause ( ) ; assertNotNull ( root ) ; if ( ! ( root instanceof IllegalArgumentException ) ) { fail ( "Wrapped exception not IAE, but " + root . getClass ( ) ) ; } } }
unit test that verifies that by default all exceptions except for jsonmappingexception are caught and wrapped .
