Search in sources :

Example 1 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.

the class ArrayRuleTest method arrayWithNonUniqueItemsProducesList.

@Test
public void arrayWithNonUniqueItemsProducesList() {
    JCodeModel codeModel = new JCodeModel();
    JPackage jpackage = codeModel._package(getClass().getPackage().getName());
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode itemsNode = mapper.createObjectNode();
    itemsNode.put("type", "number");
    ObjectNode propertyNode = mapper.createObjectNode();
    propertyNode.set("uniqueItems", BooleanNode.FALSE);
    propertyNode.set("items", itemsNode);
    Schema schema = mock(Schema.class);
    when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray"));
    when(config.isUseDoubleNumbers()).thenReturn(true);
    JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema);
    assertThat(propertyType, notNullValue());
    assertThat(propertyType.erasure(), is(codeModel.ref(List.class)));
    assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schema(org.jsonschema2pojo.Schema) JClass(com.sun.codemodel.JClass) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.

the class ArrayRuleTest method arrayWithUniqueItemsProducesSet.

@Test
public void arrayWithUniqueItemsProducesSet() {
    JCodeModel codeModel = new JCodeModel();
    JPackage jpackage = codeModel._package(getClass().getPackage().getName());
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode itemsNode = mapper.createObjectNode();
    itemsNode.put("type", "integer");
    ObjectNode propertyNode = mapper.createObjectNode();
    propertyNode.set("uniqueItems", BooleanNode.TRUE);
    propertyNode.set("items", itemsNode);
    JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, mock(Schema.class));
    assertThat(propertyType, notNullValue());
    assertThat(propertyType.erasure(), is(codeModel.ref(Set.class)));
    assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Integer.class.getName()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JClass(com.sun.codemodel.JClass) Schema(org.jsonschema2pojo.Schema) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project OpenAM by OpenRock.

the class SubjectTypesResource method jsonify.

/**
     * Transforms a subclass of {@link EntitlementSubject} in to a JsonSchema representation.
     * This schema is then combined with the Subject's name (taken as the resourceId) and all this is
     * compiled together into a new {@link JsonValue} object until "title" and "config" fields respectively.
     *
     * @param subjectClass The class whose schema to produce.
     * @param resourceId The ID of the resource to return
     * @return A JsonValue containing the schema of the EntitlementSubject
     */
private JsonValue jsonify(Class<? extends EntitlementSubject> subjectClass, String resourceId, boolean logical) {
    try {
        final JsonSchema schema = mapper.generateJsonSchema(subjectClass);
        //this will remove the 'subjectName' attribute from those subjects which incorporate it unnecessarily
        final JsonNode node = schema.getSchemaNode().get("properties");
        if (node instanceof ObjectNode) {
            final ObjectNode alter = (ObjectNode) node;
            alter.remove("subjectName");
        }
        return JsonValue.json(JsonValue.object(JsonValue.field(JSON_OBJ_TITLE, resourceId), JsonValue.field(JSON_OBJ_LOGICAL, logical), JsonValue.field(JSON_OBJ_CONFIG, schema)));
    } catch (JsonMappingException e) {
        if (debug.errorEnabled()) {
            debug.error("SubjectTypesResource :: JSONIFY - Error applying " + "jsonification to the Subject class representation.", e);
        }
        return null;
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 4 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class SwaggerSchema method allowJsonRefInSecurityDefinitionsObject.

protected void allowJsonRefInSecurityDefinitionsObject(boolean allow) {
    ObjectNode definition = (ObjectNode) jsonRefContexts.get(SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT);
    if (allow) {
        ObjectNode propertiesNode = definition.putObject("properties");
        propertiesNode.putObject("$ref").put("type", "string");
    } else {
        definition.remove("properties");
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 5 with ObjectNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode in project azure-sdk-for-java by Azure.

the class DeployUsingARMTemplateWithTags method validateAndAddFieldValue.

private static void validateAndAddFieldValue(String type, String fieldValue, String fieldName, String errorMessage, JsonNode tmp) throws IllegalAccessException {
    // Add count variable for loop....
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectNode parameter = mapper.createObjectNode();
    parameter.put("type", type);
    if (type == "int") {
        parameter.put("defaultValue", Integer.parseInt(fieldValue));
    } else {
        parameter.put("defaultValue", fieldValue);
    }
    ObjectNode.class.cast(tmp.get("parameters")).replace(fieldName, parameter);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2194 JsonNode (com.fasterxml.jackson.databind.JsonNode)492 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)488 Test (org.junit.Test)471 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)350 IOException (java.io.IOException)195 ArrayList (java.util.ArrayList)104 HashMap (java.util.HashMap)102 Map (java.util.Map)98 StringEntity (org.apache.http.entity.StringEntity)93 Deployment (org.activiti.engine.test.Deployment)85 Test (org.testng.annotations.Test)76 List (java.util.List)74 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)69 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)65 HttpPost (org.apache.http.client.methods.HttpPost)53 Task (org.activiti.engine.task.Task)51 File (java.io.File)50 JCodeModel (com.sun.codemodel.JCodeModel)45 TextNode (com.fasterxml.jackson.databind.node.TextNode)44