Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Collections;
import java.util.Map;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Main {
    public static ObjectMapper mapper = new ObjectMapper();

    public static Map<String, Object> fromJson(String params) {
        try {
            JavaType jType = getCollectionType(Map.class, String.class, Object.class);
            return mapper.readValue(params, jType);
        } catch (Exception e) {
            return Collections.emptyMap();
        }
    }

    public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
        return mapper.getTypeFactory().constructParametricType(collectionClass, elementClasses);
    }
}