本文整理汇总了Java中com.fasterxml.jackson.databind.JsonNode.get方法的典型用法代码示例。如果您正苦于以下问题:Java JsonNode.get方法的具体用法?Java JsonNode.get怎么用?Java JsonNode.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonNode
的用法示例。
在下文中一共展示了JsonNode.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readUsers
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private void readUsers(final Map<String, User> rolesToUsers, final JsonNode node,
final Map<String, Role> roleMap) {
for (JsonNode usersNode : node.get("users")) {
User user = new User();
user.name = usersNode.get("name").asText();
if (usersNode.has("password")) {
user.password = usersNode.get("password").asText();
} else {
user.password = user.name;
}
for (JsonNode rolesNode : usersNode.get("roles")) {
user.roles.add(roleMap.get(rolesNode.asText()));
}
rolesToUsers.put(user.name, user);
}
}
示例2: checkForInvalidMongoKeys
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private String checkForInvalidMongoKeys ( JsonNode definitionNode, String location ) {
// TODO Auto-generated method stub
StringBuffer resultsBuf = new StringBuffer( "" );
Iterator<String> names = definitionNode.fieldNames();
while (names.hasNext()) {
String name = names.next();
// if ( logger.isDebugEnabled() )
// logger.debug("key: " + name + " location: " + location);
JsonNode fieldValue = definitionNode.get( name );
if ( fieldValue.isObject() ) {
resultsBuf.append( checkForInvalidMongoKeys( fieldValue, location + "," + name ) );
} else if ( name.contains( "." ) ) {
resultsBuf.append( CSAP.CONFIG_PARSE_WARN + " - \".\" should not appear in: \"" + name
+ "\" in definition file: " + location + "\n" );
}
}
// resultsBuf.append(CONFIG_PARSE_WARN +
// " - invalid key in definition file: " + fileName + "\n");
return resultsBuf.toString();
}
示例3: configureRemoteCollection
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public boolean configureRemoteCollection ( int collectHostIndex, StringBuffer resultsBuf ) {
JsonNode remoteCollectionsDefinition = getAttributeAsJson( ServiceAttributes.remoteCollections );
JsonNode remoteDefinition = remoteCollectionsDefinition.get( collectHostIndex );
if ( !remoteDefinition.isObject() || !remoteDefinition.has( "host" ) || !remoteDefinition.has( "port" ) ) {
logger.error( "Invalid configuration: {}", remoteDefinition.toString() );
updateServiceParseResults(
resultsBuf, CSAP.CONFIG_PARSE_WARN,
getErrorHeader()
+ "Invalid format for " + ServiceAttributes.remoteCollections
+ " expected: host and port, found: " + remoteCollectionsDefinition.toString() );
return false;
}
setCollectHost( remoteDefinition.get( "host" ).asText() );
setCollectPort( remoteDefinition.get( "port" ).asText() );
return true;
}
示例4: getAllBookings
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public static Collection<Booking> getAllBookings() {
JsonNode response = HttpHelper.connect(BOOKINGS_DATABASE + ALL_QUERY, "GET", null);
if (response == null) {
return null;
}
int size = response.get("total_rows").asInt();
System.out.println("Number of bookings: " + size);
JsonNode bookings = response.get("rows");
List<Booking> allBookings = new ArrayList<Booking>(size);
for (int i = 0; i < size; i++) {
try {
JsonNode bookingJson = HttpHelper.connect(BOOKINGS_DATABASE + "/" + bookings.get(i).get("id").asText(), "GET", null);
Booking booking = mapper.treeToValue(bookingJson,Booking.class);
System.out.println("Booking[" + i + "] " + booking);
//todo: add id
allBookings.add(booking);
} catch (IOException e) {
e.printStackTrace();
}
}
return allBookings;
}
示例5: assertNavNode
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public JsonNode assertNavNode(JsonNode parentNode, int index, String uuid, String name, String[][] tabs)
{
JsonNode childNode = parentNode.get(index);
Assert.assertEquals(childNode.get("uuid").textValue(), uuid);
Assert.assertEquals(childNode.get("name").textValue(), name);
JsonNode tabsNode = childNode.get("tabs");
int tabIndex = 0;
for( String[] tab : tabs )
{
JsonNode tab1 = tabsNode.get(tabIndex);
Assert.assertEquals(tab1.get("name").textValue(), tab[0]);
Assert.assertEquals(tab1.get("attachment").get("$ref").textValue(), tab[1]);
JsonNode viewer = tab1.get("viewer");
if( viewer == null && tab[2] != null )
{
Assert.assertTrue(tab[2].isEmpty());
}
else
{
Assert.assertEquals(viewer.textValue(), tab[2]);
}
tabIndex++;
}
return childNode.get("nodes");
}
示例6: getValues
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static List<List<?>> getValues(BeakerObjectConverter parent, JsonNode n, ObjectMapper mapper) throws IOException {
List<List<?>> values = null;
List<String> classes = null;
if (n.has("types"))
classes = mapper.readValue(n.get("types").asText(), List.class);
if (n.has("values")) {
JsonNode nn = n.get("values");
values = new ArrayList<List<?>>();
if (nn.isArray()) {
for (JsonNode nno : nn) {
if (nno.isArray()) {
ArrayList<Object> val = new ArrayList<Object>();
for (int i = 0; i < nno.size(); i++) {
JsonNode nnoo = nno.get(i);
Object obj = parent.deserialize(nnoo, mapper);
val.add(TableDisplayDeSerializer.getValueForDeserializer(obj, classes != null && classes.size() > i ? classes.get(i) : null));
}
values.add(val);
}
}
}
}
return values;
}
示例7: getSelectRoot_GET
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private String getSelectRoot_GET(JsonNode queryField) {
String targetName = queryField.get("targetName").asText();
String targetURI = schema.getTypes().get(targetName).getId();
String graphID = ((SPARQLEndpointService) schema.getQueryFields().get(queryField.get("name").asText()).service()).getGraph();
String nodeId = queryField.get("nodeId").asText();
String limitOffsetSTR = limitOffsetSTR(queryField);
String selectTriple = tripleSTR(varSTR(nodeId), RDF_TYPE_URI, uriSTR(targetURI));
String rootSubquery = selectSubquerySTR(nodeId, selectTriple, limitOffsetSTR);
JsonNode subfields = queryField.get("fields");
String whereClause = getSubQueries(subfields);
String selectQuery = selectQuerySTR(rootSubquery + whereClause, graphID);
return selectQuery;
}
示例8: serializeStrokeTypeListStems_resultJsonHasStyles
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Test
public void serializeStrokeTypeListStems_resultJsonHasStyles() throws IOException {
//when
Stems stems = new Stems();
stems.setStyle(Arrays.asList(StrokeType.SOLID, StrokeType.DASHDOT));
stemsSerializer.serialize(stems, jgen, new DefaultSerializerProvider.Impl());
jgen.flush();
//then
JsonNode actualObj = mapper.readTree(sw.toString());
Assertions.assertThat(actualObj.has("styles")).isTrue();
ArrayNode arrayNode = (ArrayNode) actualObj.get("styles");
Assertions.assertThat(arrayNode.get(1).asText()).isEqualTo("DASHDOT");
}
示例9: apply
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public Collection<String> apply(Device device) throws Exception {
StringWriter stringWriter = new StringWriter();
writer.writeValue(stringWriter, device);
JsonNode node = mapper.readTree(stringWriter.toString());
Collection<String> strings = new ArrayList<>();
for (String s : names) {
JsonNode jsonNode = node.get(s);
strings.add(jsonNode.asText("invalid"));
}
return strings;
}
示例10: moveBuffersToBody
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
public void moveBuffersToBody(ObjectNode scene, GlbBody body) throws Exception {
// Modify the GLTF data to reference the buffer in the body instead of
// external references.
JsonNode buffersNode = scene.get("buffers");
Iterator<String> fieldIter = buffersNode.fieldNames();
while (fieldIter.hasNext()) {
String fieldKey = fieldIter.next();
JsonNode gltfBufferNode = buffersNode.get(fieldKey);
JsonNode typeNode = gltfBufferNode.get("type");
String typeText = typeNode.asText();
if (typeText != null && !typeText.equals("arraybuffer")) {
throw new Exception("buffer type " + typeText + " not supported: " + fieldKey);
}
JsonNode uriNode = gltfBufferNode.get("uri");
String uri = uriNode.asText();
JsonNode byteLengthNode = gltfBufferNode.get("byteLength");
int byteLength = byteLengthNode.asInt();
Part part = body.add(uri, byteLength);
JsonNode extrasNode = gltfBufferNode.get("extras");
if (extrasNode == null) {
extrasNode = jsonNodeFactory.objectNode();
((ObjectNode) gltfBufferNode).set("extras", extrasNode);
}
((ObjectNode) extrasNode).put("byteOffset", part.offset);
}
}
示例11: serializeFillsCategoryPoints_resultJsonHasFills
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Test
public void serializeFillsCategoryPoints_resultJsonHasFills() throws IOException {
//when
CategoryPoints categoryPoints = new CategoryPoints();
categoryPoints.setFill(Arrays.asList(false, true, false));
categoryPointsSerializer.serialize(categoryPoints, jgen, new DefaultSerializerProvider.Impl());
jgen.flush();
//then
JsonNode actualObj = mapper.readTree(sw.toString());
Assertions.assertThat(actualObj.has("fills")).isTrue();
ArrayNode arrayNode = (ArrayNode) actualObj.get("fills");
Assertions.assertThat(arrayNode.get(1).asBoolean()).isTrue();
}
示例12: testSchemaHistory
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Ignore("need config") @Test
public void testSchemaHistory()
{
Result result = controllers.api.v1.SchemaHistory.getPagedDatasets();
assertThat(status(result)).isEqualTo(OK);
JsonNode node = Json.parse(contentAsString(result));
assertThat(node.isContainerNode());
assertThat(node.get("status").asText()).isEqualTo("ok");
JsonNode dataNode = node.get("data");
assertThat(dataNode.isContainerNode());
long count = dataNode.get("count").asLong();
assertThat(count > 0);
JsonNode datasetsNode = dataNode.get("datasets");
assertThat(datasetsNode.isArray());
JsonNode firstDatasetNode = ((ArrayNode) datasetsNode).get(0);
assertThat(firstDatasetNode.isContainerNode());
int datasetId = firstDatasetNode.get("id").asInt();
assertThat(datasetId > 0);
result = controllers.api.v1.SchemaHistory.getSchemaHistory(datasetId);
assertThat(status(result)).isEqualTo(OK);
JsonNode historyNode = Json.parse(contentAsString(result));
assertThat(historyNode.isContainerNode());
assertThat(historyNode.get("status").asText()).isEqualTo("ok");
JsonNode historyDataNode = node.get("data");
assertThat(historyDataNode.isArray());
}
示例13: getPermittedCourses
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
public CompletionStage<Collection<String>> getPermittedCourses(User user) throws MalformedURLException {
URL url = parseUrl(user);
WSRequest request = wsClient.url(url.toString().split("\\?")[0]);
if (url.getQuery() != null) {
request = request.setQueryString(url.getQuery());
}
RemoteFunction<WSResponse, Collection<String>> onSuccess = response -> {
JsonNode root = response.asJson();
if (root.has("exception")) {
throw new RemoteException(root.get("exception").asText());
} else if (root.has("data")) {
Set<String> results = new HashSet<>();
for (JsonNode course : root.get("data")) {
if (course.has("course_code")) {
results.add(course.get("course_code").asText());
} else {
Logger.warn("Unexpected content {}", course.asText());
}
}
return results;
} else {
Logger.warn("Unexpected content {}", root.asText());
throw new RemoteException("sitnet_request_timed_out");
}
};
return request.get().thenApplyAsync(onSuccess);
}
示例14: langFilterSTR
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
private String langFilterSTR(JsonNode field) {
final String PATTERN = "FILTER (lang(%s) = \"%s\") . ";
String nodeVar = varSTR(field.get("nodeId").asText());
JsonNode args = field.get("args");
String langPattern = (args.has("lang")) ? String.format(PATTERN, nodeVar, args.get("lang").asText()) : "";
return langPattern;
}
示例15: matchesSafely
import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
// check master node identifier
String jsonNodeId = jsonNode.get("master") != null ? jsonNode.get("master").asText() : null;
String nodeId = roleInfo.master().id();
if (!StringUtils.equals(jsonNodeId, nodeId)) {
description.appendText("master's node id was " + jsonNodeId);
return false;
}
// check backup nodes size
JsonNode jsonBackupNodeIds = jsonNode.get("backups");
if (jsonBackupNodeIds.size() != roleInfo.backups().size()) {
description.appendText("backup nodes size was " + jsonBackupNodeIds.size());
return false;
}
// check backup nodes' identifier
for (NodeId backupNodeId : roleInfo.backups()) {
boolean backupFound = false;
for (int idx = 0; idx < jsonBackupNodeIds.size(); idx++) {
if (backupNodeId.id().equals(jsonBackupNodeIds.get(idx).asText())) {
backupFound = true;
break;
}
}
if (!backupFound) {
description.appendText("backup not found " + backupNodeId.id());
return false;
}
}
return true;
}