io.klerch.alexa.state.utils.ConversionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of alexa-skills-kit-states-java Show documentation
Show all versions of alexa-skills-kit-states-java Show documentation
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.
/**
* 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<>();
}
}
}