// Copyright (c) 2003-2014, Jodd Team (jodd.org). All Rights Reserved.

package jodd.json;

import jodd.introspector.ClassDescriptor;
import jodd.introspector.ClassIntrospector;
import jodd.introspector.CtorDescriptor;
import jodd.typeconverter.TypeConverterManager;

import java.util.HashMap;
import java.util.Map;

/**
 * Some common utilities.
 */
public class JsonParserUtil {

	/**
	 * Creates new object or a <code>HashMap</code> if type is not specified.
	 */
	public static Object newObjectInstance(Class targetType) {
		if (targetType == null) {
			return new HashMap();
		}

		if (targetType == Map.class) {
			return new HashMap();
		}

		ClassDescriptor cd = ClassIntrospector.lookup(targetType);

		try {
			CtorDescriptor ctorDescriptor = cd.getDefaultCtorDescriptor(true);
			return ctorDescriptor.getConstructor().newInstance();
		} catch (Exception e) {
			throw new JsonException(e);
		}
	}

	/**
	 * Converts type of the given value.
	 */
	public static Object convertType(Object value, Class targetType) {
		Class valueClass = value.getClass();

		if (valueClass == targetType) {
			return value;
		}

		try {
			return TypeConverterManager.convertType(value, targetType);
		}
		catch (Exception ex) {
			throw new JsonException("Type conversion failed", ex);
		}
	}


}
@@ -703,25 +703,16 @@
 Type);%0A%0A
-%09%09try %7B%0A%09
 %09%09CtorDe
@@ -772,16 +772,155 @@
 (true);%0A
+%09%09if (ctorDescriptor == null) %7B%0A%09%09%09throw new JsonException(%22Default ctor not found for: %22 + targetType.getClass().getName());%0A%09%09%7D%0A%0A%09%09try %7B%0A
 %09%09%09retur

Add human error message