java 反射获得私有属性的对象

       
       
        pbulic class Json2Body () {
       
         private ObjectMapper om;
         public Json2Body() {
          om = new ObjectMapper();
          
         }
         
         pulbic static main() {
          
          try {
              Json2Body json2Body = new Json2Body();


              Field f = json2Body.getClass().getDeclaredField("om");
              f.setAccessible(true);

              ObjectMapper om = (ObjectMapper) f.get(json2Body);


          } catch (NoSuchFieldException e) {
              Assert.fail();
          }
         
         }
        }

你可能感兴趣的:(java 反射获得私有属性的对象)