@Test public void testBeanSerialize() throws Exception { Bean bean = new Bean(); bean.setDate(new Date()); bean.setStatus(PersonStatus.ENABLED); bean.setType(Bean.class); bean.setArray(new Phone[]{}); Collection<Phone> collection = new ArrayList<Phone>(); bean.setCollection(collection); Phone phone = new Phone(); collection.add(phone); Map<String, FullAddress> map = new HashMap<String, FullAddress>(); FullAddress address = new FullAddress(); map.put("first", address); bean.setAddresses(map); JavaBeanDescriptor descriptor = JavaBeanSerializeUtil.serialize(bean, JavaBeanAccessor.METHOD); Assert.assertTrue(descriptor.isBeanType()); assertEqualsPrimitive(bean.getDate(), descriptor.getProperty("date")); assertEqualsEnum(bean.getStatus(), descriptor.getProperty("status")); Assert.assertTrue(((JavaBeanDescriptor)descriptor.getProperty("type")).isClassType()); Assert.assertEquals(Bean.class.getName(), ((JavaBeanDescriptor)descriptor.getProperty("type")).getClassNameProperty()); Assert.assertTrue(((JavaBeanDescriptor)descriptor.getProperty("array")).isArrayType()); Assert.assertEquals(0, ((JavaBeanDescriptor)descriptor.getProperty("array")).propertySize()); JavaBeanDescriptor property = (JavaBeanDescriptor)descriptor.getProperty("collection"); Assert.assertTrue(property.isCollectionType()); Assert.assertEquals(1, property.propertySize()); property = (JavaBeanDescriptor)property.getProperty(0); Assert.assertTrue(property.isBeanType()); Assert.assertEquals(Phone.class.getName(), property.getClassName()); Assert.assertEquals(0, property.propertySize()); property = (JavaBeanDescriptor)descriptor.getProperty("addresses"); Assert.assertTrue(property.isMapType()); Assert.assertEquals(bean.getAddresses().getClass().getName(), property.getClassName()); Assert.assertEquals(1, property.propertySize()); Map.Entry<Object, Object> entry = property.iterator().next(); Assert.assertTrue(((JavaBeanDescriptor)entry.getKey()).isPrimitiveType()); Assert.assertEquals("first", ((JavaBeanDescriptor)entry.getKey()).getPrimitiveProperty()); Assert.assertTrue(((JavaBeanDescriptor)entry.getValue()).isBeanType()); Assert.assertEquals(FullAddress.class.getName(), ((JavaBeanDescriptor)entry.getValue()).getClassName()); Assert.assertEquals(0, ((JavaBeanDescriptor)entry.getValue()).propertySize()); }
public static JavaBeanDescriptor serialize(Object obj) { return serialize(obj, JavaBeanAccessor.FIELD); }
JavaBeanSerializeUtil { public static JavaBeanDescriptor serialize(Object obj) { return serialize(obj, JavaBeanAccessor.FIELD); } }
JavaBeanSerializeUtil { public static JavaBeanDescriptor serialize(Object obj) { return serialize(obj, JavaBeanAccessor.FIELD); } private  JavaBeanSerializeUtil(); }
JavaBeanSerializeUtil { public static JavaBeanDescriptor serialize(Object obj) { return serialize(obj, JavaBeanAccessor.FIELD); } private  JavaBeanSerializeUtil(); static JavaBeanDescriptor serialize(Object obj); static JavaBeanDescriptor serialize(Object obj, JavaBeanAccessor accessor); static Object deserialize(JavaBeanDescriptor beanDescriptor); static Object deserialize(JavaBeanDescriptor beanDescriptor, ClassLoader loader); static Class<?> name2Class(ClassLoader loader, String name); }
JavaBeanSerializeUtil { public static JavaBeanDescriptor serialize(Object obj) { return serialize(obj, JavaBeanAccessor.FIELD); } private  JavaBeanSerializeUtil(); static JavaBeanDescriptor serialize(Object obj); static JavaBeanDescriptor serialize(Object obj, JavaBeanAccessor accessor); static Object deserialize(JavaBeanDescriptor beanDescriptor); static Object deserialize(JavaBeanDescriptor beanDescriptor, ClassLoader loader); static Class<?> name2Class(ClassLoader loader, String name);  }