Package com.sequenceiq.cloudbreak.controller.json

Source Code of com.sequenceiq.cloudbreak.controller.json.JsonHelper

package com.sequenceiq.cloudbreak.controller.json;

import java.io.IOException;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sequenceiq.cloudbreak.controller.InternalServerException;

@Component
public class JsonHelper {

    public JsonNode createJsonFromString(String jsonString) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            JsonFactory factory = mapper.getFactory();
            JsonParser jp = factory.createParser(jsonString);
            return mapper.readTree(jp);
        } catch (IOException e) {
            throw new InternalServerException("Failed to parse JSON string.", e);
        }
    }

}
TOP

Related Classes of com.sequenceiq.cloudbreak.controller.json.JsonHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.