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;
}
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");
}
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;
}
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;
});
}
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;
}
Aggregations