All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kt3k.straw.StrawUtil Maven / Gradle / Ivy

The newest version!
package org.kt3k.straw;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

public class StrawUtil {

	public static Gson gson = new Gson();

	public static String objToJson(Object value) {
		return gson.toJson(value);
	}

	public static  T jsonToObj(String json, Class type) throws JsonSyntaxException {
		return gson.fromJson(json, type);
	}

	public static  String join(T[] array, String sep) {
		Integer len = array.length;

		if (len == 0) {
			return "";
		}

		StringBuilder sb = new StringBuilder();

		sb.append(array[0].toString());

		for (int i = 1; i < len; i++) {
			sb.append(sep);
			sb.append(array[i].toString());
		}

		return sb.toString();
	}

	public static Boolean hasAnnotation(Method method, Class annotation) {
		return method.getAnnotation(annotation) != null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy