
com.megaport.api.util.JsonConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of client Show documentation
Show all versions of client Show documentation
This library is a Java wrapper for the Megaport API.
The newest version!
package com.megaport.api.util;
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by adam.wells on 22/06/2016.
*/
public class JsonConverter {
private static JsonFactory factory = new JsonFactory();
private static ObjectMapper mapper = new ObjectMapper(factory);
public static TypeReference> typeRef = new TypeReference>() {};
public static HashMap fromJson(String jsonString) {
try {
return mapper.readValue(new ByteArrayInputStream(jsonString.getBytes("UTF-8")), typeRef);
} catch (IOException e) {
return new HashMap<>();
}
}
public static List fromJsonDataAsList(String jsonString, Class typeReference) {
List result = new ArrayList<>();
HashMap map = fromJson(jsonString);
if (!map.get("data").equals("[]")){
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy