com.aeontronix.enhancedmule.tools.util.JsonHelper Maven / Gradle / Ivy
/*
* Copyright (c) Aeontronix 2019
*/
package com.aeontronix.enhancedmule.tools.util;
import com.aeontronix.enhancedmule.tools.AnypointClient;
import com.aeontronix.enhancedmule.tools.AnypointObject;
import com.aeontronix.enhancedmule.tools.InvalidJsonException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class JsonHelper implements Serializable {
private ObjectMapper jsonMapper = createMapper();
private AnypointClient client;
public JsonHelper(AnypointClient client) {
this.client = client;
}
public ObjectMapper getJsonMapper() {
return jsonMapper;
}
public byte[] toJson(Object obj) {
try (ByteArrayOutputStream tmp = new ByteArrayOutputStream()) {
jsonMapper.writeValue(tmp, obj);
return tmp.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public Map toJsonMap(String json) {
try {
return jsonMapper.readValue(json, new TypeReference
© 2015 - 2025 Weber Informatics LLC | Privacy Policy