Here you can find the source of toPrimitiveWrapper(String primitiveJson, Class
public static <T> T toPrimitiveWrapper(String primitiveJson, Class<T> clazz)
//package com.java2s; //License from project: Apache License public class Main { public static <T> T toPrimitiveWrapper(String primitiveJson, Class<T> clazz) { Object result = null;// ww w . jav a 2s . c om if (clazz.isAssignableFrom(Integer.class)) { result = Integer.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Long.class)) { result = Long.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Short.class)) { result = Short.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Float.class)) { result = Float.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Double.class)) { result = Double.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Byte.class)) { result = Byte.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Boolean.class)) { result = Boolean.valueOf(primitiveJson); } else if (clazz.isAssignableFrom(Character.class)) { result = Character.valueOf(primitiveJson.charAt(0)); } else if (clazz.isAssignableFrom(Void.class)) { result = ""; } return clazz.cast(result); } }