Search in sources :

Example 86 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project graphhopper by graphhopper.

the class GHMatrixBatchRequester method createPointList.

protected final ArrayNode createPointList(List<GHPoint> list) {
    // new ArrayList<>(list.size())
    ArrayNode outList = factory.arrayNode(list.size());
    for (GHPoint p : list) {
        ArrayNode entry = factory.arrayNode(2);
        entry.add(p.lon);
        entry.add(p.lat);
        outList.add(entry);
    }
    return outList;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 87 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project graphhopper by graphhopper.

the class NearestServletIT method testBasicNearestQuery.

@Test
public void testBasicNearestQuery() throws Exception {
    JsonNode json = nearestQuery("point=42.554851,1.536198");
    assertFalse(json.has("error"));
    ArrayNode point = (ArrayNode) json.get("coordinates");
    assertTrue("returned point is not 2D: " + point, point.size() == 2);
    double lon = point.get(0).asDouble();
    double lat = point.get(1).asDouble();
    assertTrue("nearest point wasn't correct: lat=" + lat + ", lon=" + lon, lat == 42.55483907636756 && lon == 1.5363742288086868);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 88 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project graphhopper by graphhopper.

the class NearestServletWithEleIT method testWithEleQuery.

@Test
public void testWithEleQuery() throws Exception {
    JsonNode json = nearestQuery("point=43.730864,7.420771&elevation=true");
    assertFalse(json.has("error"));
    ArrayNode point = (ArrayNode) json.get("coordinates");
    assertTrue("returned point is not 3D: " + point, point.size() == 3);
    double lon = point.get(0).asDouble();
    double lat = point.get(1).asDouble();
    double ele = point.get(2).asDouble();
    assertTrue("nearest point wasn't correct: lat=" + lat + ", lon=" + lon + ", ele=" + ele, lat == 43.73070006215647 && lon == 7.421392181993846 && ele == 66.0);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 89 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project cas by apereo.

the class OAuth20ProfileControllerTests method verifyOKWithExpiredTicketGrantingTicket.

@Test
public void verifyOKWithExpiredTicketGrantingTicket() throws Exception {
    final Map<String, Object> map = new HashMap<>();
    map.put(NAME, VALUE);
    final List<String> list = Arrays.asList(VALUE, VALUE);
    map.put(NAME2, list);
    final Principal principal = CoreAuthenticationTestUtils.getPrincipal(ID, map);
    final Authentication authentication = getAuthentication(principal);
    final AccessToken accessToken = accessTokenFactory.create(RegisteredServiceTestUtils.getService(), authentication, new MockTicketGrantingTicket("casuser"), new ArrayList<>());
    accessToken.getTicketGrantingTicket().markTicketExpired();
    this.ticketRegistry.addTicket(accessToken);
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuth20Constants.PROFILE_URL);
    mockRequest.setParameter(OAuth20Constants.ACCESS_TOKEN, accessToken.getId());
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ResponseEntity<String> entity = oAuth20ProfileController.handleRequest(mockRequest, mockResponse);
    assertEquals(HttpStatus.OK, entity.getStatusCode());
    assertEquals(CONTENT_TYPE, mockResponse.getContentType());
    final ObjectNode expectedObj = MAPPER.createObjectNode();
    final ObjectNode attrNode = MAPPER.createObjectNode();
    attrNode.put(NAME, VALUE);
    final ArrayNode values = MAPPER.createArrayNode();
    values.add(VALUE);
    values.add(VALUE);
    attrNode.put(NAME2, values);
    expectedObj.put("id", ID);
    expectedObj.put("attributes", attrNode);
    final JsonNode receivedObj = MAPPER.readTree(entity.getBody());
    assertEquals(expectedObj.get("id").asText(), receivedObj.get("id").asText());
    final JsonNode expectedAttributes = expectedObj.get(ATTRIBUTES_PARAM);
    final JsonNode receivedAttributes = receivedObj.get(ATTRIBUTES_PARAM);
    assertEquals(expectedAttributes.findValue(NAME).asText(), receivedAttributes.findValue(NAME).asText());
    assertEquals(expectedAttributes.findValues(NAME2), receivedAttributes.findValues(NAME2));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) Authentication(org.apereo.cas.authentication.Authentication) AccessToken(org.apereo.cas.ticket.accesstoken.AccessToken) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Principal(org.apereo.cas.authentication.principal.Principal) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 90 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project atlasmap by atlasmap.

the class JsonFieldWriter method createParentNode.

private ObjectNode createParentNode(ObjectNode parentNode, String parentSegment, String segment) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating parent node '" + segment + "' under previous parent '" + parentSegment + "' (" + parentNode.getClass().getName() + ")");
    }
    ObjectNode childNode = null;
    String cleanedSegment = AtlasPath.cleanPathSegment(segment);
    if (AtlasPath.isCollectionSegment(segment)) {
        ArrayNode arrayChild = parentNode.putArray(cleanedSegment);
        int index = AtlasPath.indexOfSegment(segment);
        if (arrayChild.size() < (index + 1)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Object Array is too small, resizing to accomodate index: " + index + ", current array: " + arrayChild);
            }
            // the index available
            while (arrayChild.size() < (index + 1)) {
                arrayChild.addObject();
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Object Array after resizing: " + arrayChild);
            }
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("Created wrapper parent array node '" + segment + "': " + arrayChild);
        }
        childNode = (ObjectNode) arrayChild.get(index);
    } else {
        childNode = parentNode.putObject(cleanedSegment);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Parent Node '" + parentSegment + "' after adding child parent node '" + segment + "':" + parentNode);
    }
    return childNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20