src/main/java/com/rockagen/commons/util/JsonUtil.java
public static <T> String toJson(T obj) {
		StringWriter writer = new StringWriter();
		String jsonStr = "";
		JsonGenerator gen = null;
		try {
			gen = getJsonFactory().createGenerator(writer);
			getMapper().writeValue(gen, obj);
			writer.flush();
			jsonStr = writer.toString();

		} catch (IOException e) {
			log.error("{}", e.getMessage(), e);
		} finally {
			if (gen != null) {
				try {
					gen.close();
				} catch (IOException e) {
				}
			}

		}
		return jsonStr;
	}
public static <T> String toJson(T obj) {
		StringWriter writer = new StringWriter();
		String jsonStr = "";
		JsonGenerator gen = null;
		try {
			gen = getJsonFactory().createGenerator(writer);
			getMapper().writeValue(gen, obj);
			writer.flush();
			jsonStr = writer.toString();

		} catch (IOException e) {
			log.error("{}", e.getMessage(), e);
		} finally {
			if (gen != null) {
				try {
					gen.close();
				} catch (IOException e) {
				}
			}

		}
		return jsonStr;
	}
Bean to json string

@param obj obj
bean object
@param <T> t
@return json string