Here you can find the source of toJSON(Map
Parameter | Description |
---|---|
map | a parameter |
public static String toJSON(Map<String, Object> map)
//package com.java2s; /*//w w w. j a va2 s . c om * Copyright (c) 2017 OBiBa. All rights reserved. * * This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.text.SimpleDateFormat; import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { /** * Convert a map to a JSON string. * * @param map * @return */ public static String toJSON(Map<String, Object> map) { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd")); try { return mapper.writeValueAsString(map); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } }