/*******************************************************************************
 * Copyright (c) 2018-2019 Red Hat Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat Inc. - initial API and implementation
 *
 *******************************************************************************/
package org.eclipse.jdt.ls.core.internal;

import com.google.gson.Gson;
import com.google.gson.JsonElement;

/**
 * JSONUtility
 */
public class JSONUtility {

	/**
	 * Converts given JSON objects to given Model objects.
	 *
	 * @throws IllegalArgumentException if clazz is null
	 */
	public static <T> T toModel(Object object, Class<T> clazz){
		if(object == null){
			return null;
		}
		if(clazz == null ){
			throw new IllegalArgumentException("Class can not be null");
		}
		if (clazz.isInstance(object)) {
			return clazz.cast(object);
		}
		if(object instanceof JsonElement){
			Gson gson = new Gson();
			return gson.fromJson((JsonElement) object, clazz);
		}
		if (object instanceof String) {
			Gson gson = new Gson();
			return gson.fromJson((String) object, clazz);
		}
		return null;
	}


}

@@ -1011,76 +1011,8 @@
 %09%09%7D%0A
-%09%09if (clazz.isInstance(object)) %7B%0A%09%09%09return clazz.cast(object);%0A%09%09%7D%0A
 %09%09if
@@ -1125,24 +1125,92 @@
 clazz);%0A%09%09%7D%0A
+%09%09if (clazz.isInstance(object)) %7B%0A%09%09%09return clazz.cast(object);%0A%09%09%7D%0A
 %09%09if (object

Fix ClassCastException caused by JSONUtility.toModel method