use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class JsonParserBase method newObjectInstance.
/**
* Creates new object or a <code>HashMap</code> if type is not specified.
*/
protected Object newObjectInstance(Class targetType) {
if (targetType == null || targetType == Map.class) {
return new HashMap();
}
ClassDescriptor cd = ClassIntrospector.lookup(targetType);
CtorDescriptor ctorDescriptor = cd.getDefaultCtorDescriptor(true);
if (ctorDescriptor == null) {
throw new JsonException("Default ctor not found for: " + targetType.getName());
}
try {
return ctorDescriptor.getConstructor().newInstance();
} catch (Exception e) {
throw new JsonException(e);
}
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class BeanPrefixTest method testFieldPrefix1.
@Test
public void testFieldPrefix1() {
LifeBean lifeBean = new LifeBean();
String foo = BeanUtil.pojo.getProperty(lifeBean, "foo").toString();
assertEquals("foo", foo);
JoddIntrospector.introspector = new CachingIntrospector(true, true, true, new String[] { "_" });
foo = BeanUtil.pojo.getProperty(lifeBean, "foo").toString();
assertEquals("foo", foo);
ClassDescriptor cd = JoddIntrospector.introspector.lookup(LifeBean.class);
PropertyDescriptor[] pds = cd.getAllPropertyDescriptors();
assertEquals(3, pds.length);
assertEquals("bar", pds[0].getName());
assertEquals("_bar", pds[0].getFieldDescriptor().getName());
assertEquals("www", pds[2].getName());
assertEquals(null, pds[2].getFieldDescriptor());
JoddIntrospector.introspector = new CachingIntrospector();
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class BeanPrefixTest method testFieldPrefix1withEmpty.
@Test
public void testFieldPrefix1withEmpty() {
LifeBean lifeBean = new LifeBean();
String foo = BeanUtil.pojo.getProperty(lifeBean, "foo").toString();
assertEquals("foo", foo);
JoddIntrospector.introspector = new CachingIntrospector(true, true, true, new String[] { "_", "" });
foo = BeanUtil.pojo.getProperty(lifeBean, "foo").toString();
assertEquals("foo", foo);
ClassDescriptor cd = JoddIntrospector.introspector.lookup(LifeBean.class);
PropertyDescriptor[] pds = cd.getAllPropertyDescriptors();
assertEquals(3, pds.length);
assertEquals("bar", pds[0].getName());
assertEquals("_bar", pds[0].getFieldDescriptor().getName());
assertEquals("www", pds[2].getName());
assertEquals("www", pds[2].getFieldDescriptor().getName());
JoddIntrospector.introspector = new CachingIntrospector();
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class BeanUtilGenericsTest method testAllBeanSetters.
@Test
public void testAllBeanSetters() {
Woof woof = new Woof();
Class type = woof.getClass();
ClassDescriptor cd = ClassIntrospector.lookup(type);
PropertyDescriptor[] properties = cd.getAllPropertyDescriptors();
assertNotNull(properties);
assertEquals(7, properties.length);
}
use of jodd.introspector.ClassDescriptor in project jodd by oblac.
the class ValidationContext method addClassChecks.
/**
* Parses class annotations and adds all checks.
* @see #resolveFor(Class)
*/
public void addClassChecks(Class target) {
List<Check> list = cache.get(target);
if (list == null) {
list = new ArrayList<>();
ClassDescriptor cd = ClassIntrospector.lookup(target);
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : allProperties) {
collectPropertyAnnotationChecks(list, propertyDescriptor);
}
cache.put(target, list);
}
addAll(list);
}
Aggregations