Search in sources :

Example 6 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project torodb by torodb.

the class AbstractBackendDeserializer method deserialize.

@Override
public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    T backend = backendProvider.get();
    ObjectMapper mapper = (ObjectMapper) jp.getCodec();
    ObjectNode node = (ObjectNode) jp.getCodec().readTree(jp);
    JsonNode fieldNode = null;
    Class<? extends BackendImplementation> backendImplementationClass = null;
    Iterator<String> fieldNamesIterator = node.fieldNames();
    while (fieldNamesIterator.hasNext()) {
        String fieldName = fieldNamesIterator.next();
        if (backendImplementationClass != null) {
            throw new JsonParseException("Found multiples backend implementations but only one is " + "allowed");
        }
        fieldNode = node.get(fieldName);
        if (backend.hasBackendImplementation(fieldName)) {
            backendImplementationClass = backend.getBackendImplementationClass(fieldName);
        } else if (setterMap.containsKey(fieldName)) {
            Object value = mapper.treeToValue(fieldNode, setterMap.get(fieldName).v1());
            setterMap.get(fieldName).v2().accept(backend, value);
        } else {
            throw new SystemException("AbstractBackend " + node.fields().next() + " is not valid.");
        }
    }
    if (backendImplementationClass != null) {
        backend.setBackendImplementation(jp.getCodec().treeToValue(fieldNode, backendImplementationClass));
    }
    return backend;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SystemException(com.torodb.core.exceptions.SystemException) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(org.bson.json.JsonParseException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testIssue1261InlineSchemaExample.

@Test(description = "it should read an example within an inlined schema")
public void testIssue1261InlineSchemaExample() throws Exception {
    Operation operation = Yaml.mapper().readValue("      produces:\n" + "        - application/json\n" + "      responses:\n" + "        200:\n" + "          description: OK\n" + "          schema:\n" + "            type: object\n" + "            properties:\n" + "              id:\n" + "                type: integer\n" + "                format: int32\n" + "              name:\n" + "                type: string\n" + "            required: [id, name]\n" + "            example:\n" + "              id: 42\n" + "              name: Arthur Dent\n", Operation.class);
    Response response = operation.getResponses().get("200");
    assertNotNull(response);
    Property schema = response.getSchema();
    Object example = schema.getExample();
    assertNotNull(example);
    assertTrue(example instanceof ObjectNode);
    ObjectNode objectNode = (ObjectNode) example;
    assertEquals(objectNode.get("id").intValue(), 42);
    assertEquals(objectNode.get("name").textValue(), "Arthur Dent");
}
Also used : Response(io.swagger.models.Response) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Operation(io.swagger.models.Operation) IntegerProperty(io.swagger.models.properties.IntegerProperty) MapProperty(io.swagger.models.properties.MapProperty) Property(io.swagger.models.properties.Property) Test(org.testng.annotations.Test)

Example 8 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project spring-sync by spring-projects.

the class JsonPatchPatchConverter method convert.

/**
	 * Renders a {@link Patch} as a {@link JsonNode}.
	 * @param patch the patch
	 * @return a {@link JsonNode} containing JSON Patch.
	 */
public JsonNode convert(Patch patch) {
    List<PatchOperation> operations = patch.getOperations();
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    ArrayNode patchNode = nodeFactory.arrayNode();
    for (PatchOperation operation : operations) {
        ObjectNode opNode = nodeFactory.objectNode();
        opNode.set("op", nodeFactory.textNode(operation.getOp()));
        opNode.set("path", nodeFactory.textNode(operation.getPath()));
        if (operation instanceof FromOperation) {
            FromOperation fromOp = (FromOperation) operation;
            opNode.set("from", nodeFactory.textNode(fromOp.getFrom()));
        }
        Object value = operation.getValue();
        if (value != null) {
            opNode.set("value", MAPPER.valueToTree(value));
        }
        patchNode.add(opNode);
    }
    return patchNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FromOperation(org.springframework.sync.FromOperation) PatchOperation(org.springframework.sync.PatchOperation) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 9 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project ratpack by ratpack.

the class DefaultServerConfigBuilder method addToServer.

private static void addToServer(ConfigDataBuilder configDataBuilder, Consumer<? super ObjectNode> action) {
    configDataBuilder.add((m, f) -> {
        ObjectNode rootNode = new ObjectNode(configDataBuilder.getObjectMapper().getNodeFactory());
        ObjectNode server = rootNode.putObject("server");
        action.accept(server);
        return rootNode;
    });
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 10 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project ratpack by ratpack.

the class AbstractPropertiesConfigSource method loadConfigData.

@Override
public ObjectNode loadConfigData(ObjectMapper objectMapper, FileSystemBinding fileSystemBinding) throws Exception {
    ObjectNode rootNode = objectMapper.createObjectNode();
    Properties properties = loadProperties();
    Stream<Pair<String, String>> pairs = properties.stringPropertyNames().stream().map(key -> Pair.of(key, properties.getProperty(key)));
    if (prefix.isPresent()) {
        pairs = pairs.filter(p -> p.left.startsWith(prefix.get())).map(((Function<Pair<String, String>, Pair<String, String>>) p -> p.mapLeft(s -> s.substring(prefix.get().length()))).toFunction());
    }
    pairs.forEach(p -> populate(rootNode, p.left, p.right));
    return rootNode;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Function(ratpack.func.Function) Properties(java.util.Properties) Stream(java.util.stream.Stream) FileSystemBinding(ratpack.file.FileSystemBinding) ConfigSource(ratpack.config.ConfigSource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Optional(java.util.Optional) Pair(ratpack.func.Pair) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) Function(ratpack.func.Function) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Properties(java.util.Properties) Pair(ratpack.func.Pair)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)767 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)185 JsonNode (com.fasterxml.jackson.databind.JsonNode)165 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)165 Test (org.junit.Test)112 StringEntity (org.apache.http.entity.StringEntity)88 Deployment (org.activiti.engine.test.Deployment)84 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)67 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)64 Task (org.activiti.engine.task.Task)49 HttpPost (org.apache.http.client.methods.HttpPost)49 JCodeModel (com.sun.codemodel.JCodeModel)45 JPackage (com.sun.codemodel.JPackage)44 IOException (java.io.IOException)43 HttpPut (org.apache.http.client.methods.HttpPut)40 JType (com.sun.codemodel.JType)39 HashMap (java.util.HashMap)39 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)39 ArrayList (java.util.ArrayList)32 Map (java.util.Map)32