本文整理匯總了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();
}
}
示例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");
}
}
示例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()));
}
示例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;
}
示例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;
}
示例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;
}
示例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"));
}
示例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());
}
示例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();
}
}
示例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;
}
示例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()));
}
示例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()));
}
});
}
示例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()));
}
});
}
示例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;
}
示例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);
}