当前位置: 首页>>代码示例>>Java>>正文


Java JsonNodeType类代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.node.JsonNodeType的典型用法代码示例。如果您正苦于以下问题:Java JsonNodeType类的具体用法?Java JsonNodeType怎么用?Java JsonNodeType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonNodeType类属于com.fasterxml.jackson.databind.node包,在下文中一共展示了JsonNodeType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: treeTraversalSolution

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
public void treeTraversalSolution() {
    try {
        ObjectMapper mapper = new ObjectMapper();
        // use the ObjectMapper to read the json string and create a tree
        JsonNode node = mapper.readTree(new File("Persons.json"));
        Iterator<String> fieldNames = node.fieldNames();
        while (fieldNames.hasNext()) {
            JsonNode personsNode = node.get("persons");
            Iterator<JsonNode> elements = personsNode.iterator();
            while (elements.hasNext()) {
                JsonNode element = elements.next();
                JsonNodeType nodeType = element.getNodeType();
                
                if (nodeType == JsonNodeType.STRING) {
                    out.println("Group: " + element.textValue());
                }

                if (nodeType == JsonNodeType.ARRAY) {
                    Iterator<JsonNode> fields = element.iterator();
                    while (fields.hasNext()) {
                        parsePerson(fields.next());
                    }
                }
            }
            fieldNames.next();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-for-Data-Science,代码行数:31,代码来源:JSONExamples.java

示例2: parseResponse

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private List<FieldValues> parseResponse(final JsonNode response) {
    if (response == null || response.get("fields") == null) {
        throw new RuntimeException("Failed to parse JSON");
    }

    final JsonNode fieldsNode = response.get("fields");

    if (fieldsNode.getNodeType() == JsonNodeType.OBJECT || fieldsNode.getNodeType() == JsonNodeType.ARRAY) {
        final List<FieldValues> output = new ArrayList<>();

        for (final JsonNode node : fieldsNode) {
            try {
                final FieldValues fieldValues = objectMapper.treeToValue(node, FieldValues.class);
                output.add(fieldValues);
            } catch (final JsonProcessingException e) {
                throw new RuntimeException("Failed to parse JSON", e);
            }
        }

        return output;
    } else {
        throw new RuntimeException("Failed to parse JSON");
    }
}
 
开发者ID:hpe-idol,项目名称:java-hod-client,代码行数:25,代码来源:GetParametricValuesServiceImpl.java

示例3: testGetTasks

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
@Test
public void testGetTasks() throws Exception {
	Response response = target("/tasks").request().get();
	assertResponseStatus(response, Response.Status.OK);
	assertHeader(response.getHeaders(), HttpHeaders.CONTENT_TYPE, JsonApiMediaType.APPLICATION_JSON_API);

	JsonNode data = mapper.readTree((InputStream) response.getEntity()).get("data");
	assertThat(data.getNodeType(), is(JsonNodeType.ARRAY));
	List<Task> tasks = new ArrayList<>();
	for (JsonNode node : data) {
		tasks.add(getTaskFromJson(node));
	}
	assertThat(tasks, hasSize(1));
	final Task task = tasks.get(0);
	assertThat(task.getId(), is(1L));
	assertThat(task.getName(), is("First task"));
	assertThat(task.getProject(), is(nullValue()));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:19,代码来源:JerseyApplicationTest.java

示例4: deserialize

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
@Override
public List<GeoCoord> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode node = jp.getCodec().readTree(jp);

    if (JsonNodeType.ARRAY != node.getNodeType()) {
        throw new IOException("Unable to instantiate new GeoCoord Path Lists from JSON!");
    }

    List<GeoCoord> result = new ArrayList<>(node.size());
    for (int i = 0; i < node.size(); i++) {
        JsonNode p = node.get(i);
        double lon = p.get("longitude").asDouble();
        double lat = p.get("latitude").asDouble();
        result.add(new GeoCoord(lon, lat));
    }

    return result;
}
 
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:19,代码来源:GeoCoordListDeserializer.java

示例5: createSclarProperty

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private Property createSclarProperty(String arrayType, JsonNode node) {
	Property property = null;
	Iterator<JsonNode> nodes = node.elements();
	while (nodes.hasNext()) {
		JsonNode leafNode = nodes.next();
		JsonNodeType type = leafNode.getNodeType();
		switch (type) {
		case STRING:
			property = new StringPropertyBuilder().withExample(leafNode.asText()).build();
			break;
		case BOOLEAN:
			property = new BooleanPropertyBuilder().withExample(leafNode.asBoolean()).build();
			break;
		case NUMBER:
			if (leafNode.isInt() || leafNode.isLong()) {
				property = new IntegerPropertyBuilder().withExample(leafNode.asLong()).build();
			} else if (leafNode.isFloat() || leafNode.isDouble()) {
				property = new NumberPropertyBuilder().withExample(leafNode.asDouble()).build();
			}
			break;
		default:
			break;
		}
	}
	return property;
}
 
开发者ID:pegasystems,项目名称:api2swagger,代码行数:27,代码来源:SwaggerModelGenerator.java

示例6: removeNullNodes

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private JsonNode removeNullNodes(JsonNode node) {
    Iterator<JsonNode> iterator = node.iterator();
    while (iterator.hasNext()) {
        JsonNode next = iterator.next();
        if (next.getNodeType().equals(JsonNodeType.NULL)) {
            iterator.remove();
        }
        if (next.getNodeType().equals(JsonNodeType.ARRAY) || next.getNodeType().equals(JsonNodeType.OBJECT)) {
            JsonNode jsonNode = removeNullNodes(next);
            if (!jsonNode.iterator().hasNext()) {
                iterator.remove();
            }
        }
    }
    return node;
}
 
开发者ID:pivio,项目名称:pivio-server,代码行数:17,代码来源:DocumentController.java

示例7: shouldLoadMetrics

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
@Test
 @WithMockUser(authorities={"VIEW_DEVICE_CHART"})
 public void shouldLoadMetrics() throws Exception {
 	List<String> listMetrics = eventSchema.getFields()
	.stream()
	.filter(schemaField -> schemaField.getKnownTypes().contains(JsonNodeType.NUMBER))
	.map(m -> m.getPath()).collect(java.util.stream.Collectors.toList());

     when(deviceRegisterService.findByTenantDomainNameAndDeviceGuid(tenant.getDomainName(), DEVICE_GUID))
             .thenReturn(Device.builder().application(application).build());

     when(eventSchemaService.findKnownIncomingMetricsBy(tenant, application, DEVICE_GUID, CHANNEL, JsonNodeType.NUMBER))
.thenReturn(ServiceResponseBuilder.<List<String>>ok()
.withResult(new ArrayList<String>(listMetrics)).build());

 	getMockMvc().perform(get("/devices/visualization/loading/metrics/").param("deviceGuid", DEVICE_GUID).param("channel", CHANNEL))
 		.andExpect(model().attribute("metrics", equalTo(listMetrics)))
 		.andExpect(view().name("devices/visualization/metrics"));
 }
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:20,代码来源:DeviceVisualizationControllerTest.java

示例8: setUp

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    expectedFlattenMap = new HashMap<>();
    expectedFlattenMap.put("ts",
        JsonParsingService.JsonPathData.builder()
            .value("2016-03-03T18:15:00Z")
            .types(Arrays.asList(new JsonNodeType[] {JsonNodeType.OBJECT,JsonNodeType.STRING})).build());
    expectedFlattenMap.put("value",
        JsonParsingService.JsonPathData.builder()
                .value(31.0)
                .types(Arrays.asList(new JsonNodeType[] {JsonNodeType.OBJECT,JsonNodeType.NUMBER})).build());
    expectedFlattenMap.put("command.type",
            JsonParsingService.JsonPathData.builder()
                    .value("ButtonPressed")
                    .types(Arrays.asList(new JsonNodeType[] {JsonNodeType.OBJECT,JsonNodeType.OBJECT,JsonNodeType.STRING})).build());
    expectedFlattenMap.put("data.channels.0.name",
            JsonParsingService.JsonPathData.builder()
                    .value("channel_0")
                    .types(Arrays.asList(new JsonNodeType[] {JsonNodeType.OBJECT,JsonNodeType.OBJECT,JsonNodeType.ARRAY,JsonNodeType.OBJECT,JsonNodeType.STRING})).build());
    expectedFlattenMap.put("time",
        JsonParsingService.JsonPathData.builder()
                .value(123L)
                .types(Arrays.asList(new JsonNodeType[] {JsonNodeType.OBJECT,JsonNodeType.NUMBER})).build());
}
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:25,代码来源:JsonParsingServiceTest.java

示例9: findKnownIncomingMetricsBy

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
@Override
public ServiceResponse<List<String>> findKnownIncomingMetricsBy(Tenant tenant, Application application, String deviceGuid, String channel, JsonNodeType nodeType) {

       ServiceResponse<EventSchema> metricsResponse = findIncomingBy(tenant, application, deviceGuid, channel);
       if (metricsResponse.isOk()) {

           EventSchema schema = metricsResponse.getResult();
           List<String> listMetrics = filterMetricsByJsonType(schema, nodeType);

           return ServiceResponseBuilder.<List<String>>ok().withResult(listMetrics).build();
       } else {
           return ServiceResponseBuilder.<List<String>>error().withMessages(metricsResponse.getResponseMessages())
                   .build();
       }

   }
 
开发者ID:KonkerLabs,项目名称:konker-platform,代码行数:17,代码来源:EventSchemaServiceImpl.java

示例10: listSites

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
/**
 * List of all not-empty rooms
 * @param user the id of the person requesting the list, or null if unauthenticated
 * @param map
 * @return List of all sites, possibly filtered by owner and/or name. Will not return null.
 */
public List<JsonNode> listSites(ResourceAccessPolicy accessPolicy, String owner, String name) {
    Log.log(Level.FINER, this, "List all rooms");

    List<JsonNode> result = sites.listSites(nullEmpty(owner), nullEmpty(name));

    //we have to step through any results to remove the connectionDetails blocks.
    for(JsonNode j : result){
        JsonNode ownerNode = j.get("owner");
        if(ownerNode!=null && ownerNode.getNodeType().equals(JsonNodeType.STRING)){
            String ownerNodeString = ownerNode.textValue();
            //remove connectionDetailsBlocks unless requested by owner or the system id
            if( stripSensitiveData(accessPolicy, ownerNodeString)){
                JsonNode info = j.get("info");
                if(info.getNodeType() == JsonNodeType.OBJECT){
                    ObjectNode infoObj = (ObjectNode)info;
                    if(infoObj.has("connectionDetails")){
                        infoObj.remove("connectionDetails");
                    }
                }
            }
        }
    }
    return result;
}
 
开发者ID:gameontext,项目名称:gameon-map,代码行数:31,代码来源:MapRepository.java

示例11: testGetTasks

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
@Test
public void testGetTasks() throws Exception {
    Response response = target("/tasks").request().get();
    assertResponseStatus(response, Response.Status.OK);
    assertHeader(response.getHeaders(), HttpHeaders.CONTENT_TYPE, JsonApiMediaType.APPLICATION_JSON_API);

    JsonNode data = mapper.readTree((InputStream) response.getEntity()).get("data");
    assertThat(data.getNodeType(), is(JsonNodeType.ARRAY));
    List<Task> tasks = new ArrayList<>();
    for (JsonNode node : data) {
        tasks.add(getTaskFromJson(node));
    }
    assertThat(tasks, hasSize(1));
    final Task task = tasks.get(0);
    assertThat(task.getId(), is(1L));
    assertThat(task.getName(), is("First task"));
    assertThat(task.getProject(), is(nullValue()));
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:19,代码来源:JerseyApplicationTest.java

示例12: observeGetWrappedArray

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private Observable<ArrayNode> observeGetWrappedArray(String endpoint, String wrappingField) {
    return observeGetObject(endpoint)
        .map((ObjectNode jsonObject) -> {
            JsonNode wrappedValue = jsonObject.get(wrappingField);
            if (wrappedValue == null) {
                throw new RuntimeException(String.format("Wrapping field '%s' is null",
                        wrappingField));
            } else if (wrappedValue.getNodeType() == JsonNodeType.ARRAY) {
                return (ArrayNode) wrappedValue;
            } else {
                throw new RuntimeException(String.format(
                        "Wrappeed value '%s' is not an array, but %s",
                        wrappingField, wrappedValue.getNodeType()));
            }
        });
}
 
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:17,代码来源:RecentPurchasesHandler.java

示例13: observeGetWrappedObject

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private Observable<ObjectNode> observeGetWrappedObject(String endpoint, String wrappingField) {
    return observeGetObject(endpoint)
        .map((ObjectNode jsonObject) -> {
            JsonNode wrappedValue = jsonObject.get(wrappingField);
            if (wrappedValue == null) {
                throw new RuntimeException(String.format("Wrapping field '%s' is null",
                        wrappingField));
            } else if (wrappedValue.getNodeType() == JsonNodeType.OBJECT) {
                return (ObjectNode) wrappedValue;
            } else {
                throw new RuntimeException(String.format(
                        "Wrappeed value '%s' is not an object, but %s",
                        wrappingField, wrappedValue.getNodeType()));
            }
        });
}
 
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:17,代码来源:RecentPurchasesHandler.java

示例14: decodeAttributes

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private Map<String, String> decodeAttributes(JsonNode tree, String name) {
    final JsonNode n = tree.get(name);

    if (n == null) {
        return EMPTY_ATTRIBUTES;
    }

    if (n.getNodeType() != JsonNodeType.OBJECT) {
        return EMPTY_ATTRIBUTES;
    }

    final Map<String, String> attributes = Maps.newHashMap();

    final Iterator<Map.Entry<String, JsonNode>> iter = n.fields();

    while (iter.hasNext()) {
        final Map.Entry<String, JsonNode> e = iter.next();
        attributes.put(e.getKey(), e.getValue().asText());
    }

    return attributes;
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:23,代码来源:JsonObjectMapperDecoder.java

示例15: decodeTags

import com.fasterxml.jackson.databind.node.JsonNodeType; //导入依赖的package包/类
private Set<String> decodeTags(JsonNode tree, String name) {
    final JsonNode n = tree.get(name);

    if (n == null) {
        return EMPTY_TAGS;
    }

    if (n.getNodeType() != JsonNodeType.ARRAY) {
        return EMPTY_TAGS;
    }

    final List<String> tags = Lists.newArrayList();

    final Iterator<JsonNode> iter = n.elements();

    while (iter.hasNext()) {
        tags.add(iter.next().asText());
    }

    return Sets.newHashSet(tags);
}
 
开发者ID:spotify,项目名称:ffwd,代码行数:22,代码来源:JsonObjectMapperDecoder.java


注:本文中的com.fasterxml.jackson.databind.node.JsonNodeType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。