All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.klerch.alexa.state.utils.ConversionUtils Maven / Gradle / Ivy

Go to download

This SDK is an extension to the Alexa Skills SDK for Java. It provides a framework for managing state of POJO models in a variety of persistence stores in an Alexa skill.

There is a newer version: 1.1.0
Show newest version
/**
 * Made by Kay Lerch (https://twitter.com/KayLerch)
 *
 * Attached license applies.
 * This library is licensed under GNU GENERAL PUBLIC LICENSE Version 3 as of 29 June 2007
 */
package io.klerch.alexa.state.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.Validate;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class ConversionUtils {
    /**
     * A json-string of key-value pairs is read out as a map
     * @param json json-string of key-value pairs
     * @return a map with corresponding key-value paris
     */
    public static Map mapJson(final String json) {
        final ObjectMapper mapper = new ObjectMapper();
        if (json == null || json.isEmpty()) new HashMap<>();
        final TypeReference> typeRef = new TypeReference>() {};
        try {
            // read jsonString into map
            return mapper.readValue(json, typeRef);
        } catch (IOException e) {
            e.printStackTrace();
            return new HashMap<>();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy