Java Utililty Methods Json to Object

List of utility methods to do Json to Object

Description

The list of methods to do Json to Object are organized into topic(s).

Method

TdeserializeJson(String content, Class valueType)
deserialize Json
return new ObjectMapper().readValue(content, valueType);
Listjson2List(String json, Class beanClass)
json List
try {
    return (List<T>) objectMapper.readValue(json, getCollectionType(List.class, beanClass));
} catch (Exception e) {
    e.printStackTrace();
return null;
Mapjson2map(String jsonStr)
json string convert to map
return objectMapper.readValue(jsonStr, Map.class);
Tjson2pojo(String jsonStr, Class clazz)
json string convert to javaBean
return objectMapper.readValue(jsonStr, clazz);
BigDecimaljsonBigDecimal(JsonValue value)
json Big Decimal
if (value == null || value.getValueType() == JsonValue.ValueType.NULL)
    return null;
if (value.getValueType() == JsonValue.ValueType.NUMBER && (value instanceof JsonNumber))
    return ((JsonNumber) value).bigDecimalValue();
if (value.getValueType() == JsonValue.ValueType.STRING && (value instanceof JsonString)) {
    NumberFormat f = NumberFormat.getNumberInstance();
    if (f instanceof DecimalFormat)
        ((DecimalFormat) f).setParseBigDecimal(true);
...
ListjsonStringToList(String jsonArrStr, Class clazz)
json String To List
try {
    ObjectMapper mapper = new ObjectMapper();
    JavaType javaType = mapper.getTypeFactory().constructParametricType(List.class, clazz);
    return mapper.readValue(jsonArrStr, javaType);
} catch (Exception e) {
    return null;
TjsonToBeanDateSerializer(String jsonStr, Class cl, final String pattern)
json To Bean Date Serializer
Object obj = null;
gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
    @Override
    public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
            throws JsonParseException {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        String dateString = json.getAsString();
        try {
...
TjsonToList(String json, Class parametrized, Class... parameterClasses)
json To List
try {
    TypeFactory typeFactory = MAPPER.getTypeFactory();
    return MAPPER.readValue(json, typeFactory.constructParametricType(parametrized, parameterClasses));
} catch (Exception ex) {
    throw new RuntimeException(ex);
TjsonToList(String jsonStr, TypeReference valueTypeRef)
json To List
ObjectMapper mapper = new ObjectMapper();
try {
    return mapper.readValue(jsonStr, valueTypeRef);
} catch (Exception e) {
    e.printStackTrace();
return null;
MapjsonToMap(String src)
json To Map
try {
    return mapper.readValue(src, new TypeReference<Map<String, Object>>() {
    });
} catch (Exception e) {
    throw new RuntimeException(e);