Here you can find the source of objToJson(Object obj)
Parameter | Description |
---|---|
obj | The source Java object, usually it is a Map |
static public JsonNode objToJson(Object obj)
//package com.java2s; /*// w ww.ja v a 2 s . c om * Copyright (c) 2013, the authors. * * This file is part of 'DXFS'. * * DXFS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DXFS is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DXFS. If not, see <http://www.gnu.org/licenses/>. */ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; public class Main { static private ObjectMapper mapper = new ObjectMapper(); /** * Converts a generic Java object to a {@code JsoNode} object * @param obj The source Java object, usually it is a {@code Map} * @return The mapped {@code JsonNode} instance */ static public JsonNode objToJson(Object obj) { return mapper.valueToTree(obj); } }