Java Object to Json objToJson(Object obj)

Here you can find the source of objToJson(Object obj)

Description

Converts a generic Java object to a JsoNode object

License

Open Source License

Parameter

Parameter Description
obj The source Java object, usually it is a Map

Return

The mapped JsonNode instance

Declaration

static public JsonNode objToJson(Object obj) 

Method Source Code

//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);

    }
}

Related

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