Package com.fasterxml.jackson.databind

Examples of com.fasterxml.jackson.databind.ObjectMapper.readTree()


    }

    private void validateBlueprint(String blueprintText) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode root = mapper.readTree(blueprintText);
            if (root.path("Blueprints").isMissingNode()) {
                throw new BadRequestException("Invalid blueprint: 'Blueprints' node is missing from JSON.");
            }
            if (root.path("Blueprints").path("blueprint_name").isMissingNode()) {
                throw new BadRequestException("Invalid blueprint: 'blueprint_name' under 'Blueprints' is missing from JSON.");
View Full Code Here


    private Boolean assignableHostgroup(Cluster cluster, String hostgroup) {
        try {
            ObjectMapper mapper = new ObjectMapper();
            JsonNode root;
            root = mapper.readTree(cluster.getBlueprint().getBlueprintText());
            Iterator<JsonNode> hostGroupsIterator = root.path("host_groups").elements();
            while (hostGroupsIterator.hasNext()) {
                JsonNode hostGroup = hostGroupsIterator.next();
                if (hostGroup.path("name").asText().equals(hostgroup)) {
                    return true;
View Full Code Here

    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);
        }
    }
View Full Code Here

public class AdditionalPropertiesDeserializer extends JsonDeserializer<ObjectSchema.AdditionalProperties> {

    @Override
    public ObjectSchema.AdditionalProperties deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        ObjectMapper mapper = (ObjectMapper) jp.getCodec();
        TreeNode node = mapper.readTree(jp);
        String nodeStr = mapper.writeValueAsString(node);
        if (node instanceof ObjectNode) {
            JsonSchema innerSchema = mapper.readValue(nodeStr, JsonSchema.class);
            return new ObjectSchema.SchemaAdditionalProperties(innerSchema);
        } else if (node instanceof BooleanNode) {
View Full Code Here

                                        String sFakeCreateUser = getFakeUserCreationAddress();
                                        requestCreation = new FakeRequest(POST, sFakeCreateUser);
                                        requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
                                        requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
                                        ObjectMapper mapper = new ObjectMapper();
                                        JsonNode actualObj = mapper.readTree("{\"username\":\""+userName+"\","
                                            + "\"password\":\"test\"," 
                                            + "\"role\":\""+ roleName +"\"}");
                                        requestCreation = requestCreation.withJsonBody(actualObj);
                                        requestCreation = requestCreation.withHeader("Content-Type", "application/json");
                                        result = route(requestCreation);
View Full Code Here

                                    //tries to recreate the same role, now with description
                                        requestCreation = new FakeRequest(POST, sFakeRole);
                                        requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
                                        requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
                                        mapper = new ObjectMapper();
                                        actualObj = mapper.readTree("{\"description\":\"this is a test\"}")
                                        requestCreation = requestCreation.withJsonBody(actualObj);
                                        requestCreation = requestCreation.withHeader("Content-Type", "application/json");
                                        result = route(requestCreation);
                                        assertRoute(result, "testRoleCreate.create_the_same", Status.CREATED, null, true);
View Full Code Here

                             
                                     requestCreation = new FakeRequest(PUT, sFakeRole);
                                         requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
                                         requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
                                         mapper = new ObjectMapper();
                                         actualObj = mapper.readTree("{\"description\":\"this is new test\"}")
                                         requestCreation = requestCreation.withJsonBody(actualObj,PUT);
                                         result = route(requestCreation);
                                         assertRoute(result, "testRoleCreate.update_desc", Status.OK, null, true);
                                        
                                                                            
View Full Code Here

                                        String sFakeCreateUser = getFakeUserCreationAddress();
                                        requestCreation = new FakeRequest(POST, sFakeCreateUser);
                                        requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
                                        requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
                                        ObjectMapper mapper = new ObjectMapper();
                                        JsonNode actualObj = mapper.readTree("{\"username\":\""+userName+"\","
                                            + "\"password\":\"test\"," 
                                            + "\"role\":\""+ roleName +"\"}");
                                        requestCreation = requestCreation.withJsonBody(actualObj);
                                        requestCreation = requestCreation.withHeader("Content-Type", "application/json");
                                        result = route(requestCreation);
View Full Code Here

                                     String sFakeRegUser = "regUser_"+UUID.randomUUID();
                                         requestCreation = new FakeRequest(POST, "/admin/user");
                                         requestCreation = requestCreation.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
                                         requestCreation = requestCreation.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
                                         mapper = new ObjectMapper();
                                         actualObj = mapper.readTree("{\"username\":\""+sFakeRegUser+"\","
                                             + "\"password\":\"test\"," 
                                             + "\"role\":\"registered\"}");
                                         requestCreation = requestCreation.withJsonBody(actualObj);
                                         requestCreation = requestCreation.withHeader("Content-Type", "application/json");
                                         result = route(requestCreation);
View Full Code Here

    ObjectMapper mapper = new ObjectMapper();
    ObjectNode result = Json.newObject();
    setCallIdOnResult(request, result);
    result.put("result", "ok");
    try {
      result.put("data", mapper.readTree(stringBody));
    } catch (JsonProcessingException e) {
      result.put("data", stringBody);
    } catch (IOException e) {
      if (stringBody.isEmpty()) result.put("data", "");
      else throw new IOException("Error parsing stringBody: " + stringBody,e);
View Full Code Here

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.