/** * Creates new object or a <code>HashMap</code> if type is not specified. */ protected Object newObjectInstance(final Class targetType) { if (targetType == null || targetType == Map.class) { return mapSupplier.get(); } ClassDescriptor cd = ClassIntrospector.get().lookup(targetType); CtorDescriptor ctorDescriptor = cd.getDefaultCtorDescriptor(true); if (ctorDescriptor == null) { throw new JsonException("Default ctor not found for: " + targetType.getName()); } try { // return ClassUtil.newInstance(targetType); return ctorDescriptor.getConstructor().newInstance(); } catch (Exception e) { throw new JsonException(e); } }
ctors = cd.getAllCtorDescriptors(); assertEquals(2, ctors.length); assertNotNull(cd.getDefaultCtorDescriptor(true)); assertNull(cd.getDefaultCtorDescriptor(false)); assertNull(cd.getDefaultCtorDescriptor(false)); assertNull(cd.getDefaultCtorDescriptor(true));