Java Object to Json toJson(List list)

Here you can find the source of toJson(List list)

Description

to Json

License

Apache License

Declaration

public static <T> String toJson(List<T> list) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    public static <T> String toJson(List<T> list) {
        try {/*from  w  w  w .  j  av a 2  s.  c  o  m*/
            return new ObjectMapper().writeValueAsString(list);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static <K, V> String toJson(Map<K, V> map) {
        try {
            return new ObjectMapper().writeValueAsString(map);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return "";
    }
}

Related

  1. obj2Json(Object obj)
  2. object2Jason(Object obj)
  3. objectToString(StringBuilder bld, ObjectNode node, int depth, boolean newLine)
  4. objToJson(Object obj)
  5. toJson(Object dto)
  6. toJson(Object message)
  7. toJson(Object o)
  8. toJson(Object o)