Search in sources :

Example 61 with JsonNode

use of org.codehaus.jackson.JsonNode in project spatial-portal by AtlasOfLivingAustralia.

the class AreaAddressRadiusSelection method findAddressLatLng.

public double[] findAddressLatLng(String text) throws Exception {
    String url = StringConstants.GOOGLE_ADDRESS_LINE + URLEncoder.encode(text, StringConstants.UTF_8);
    String key = CommonData.getSettings().getProperty("google.maps.apikey", null);
    if (key != null)
        url += "&key=" + key;
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readTree(new URL(url).openStream());
    JsonNode latLngNode = node.get(StringConstants.RESULTS).get(0).get(StringConstants.GEOMETRY).get(StringConstants.LOCATION);
    return new double[] { latLngNode.get("lat").getDoubleValue(), latLngNode.get("lng").getDoubleValue() };
}
Also used : JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) URL(java.net.URL)

Example 62 with JsonNode

use of org.codehaus.jackson.JsonNode in project apex-core by apache.

the class TypeDiscoveryTest method testTypeDiscoveryMultiLevel.

@Test
public void testTypeDiscoveryMultiLevel() throws Exception {
    String[] classFilePath = OperatorDiscoveryTest.getClassFileInClasspath();
    OperatorDiscoverer od = new OperatorDiscoverer(classFilePath);
    od.buildTypeGraph();
    JSONObject Desc = od.describeClassByASM(SubSubClass.class.getName());
    JSONArray json = Desc.getJSONArray("portTypeInfo");
    String debug = "\n(ASM)type info for " + SubSubClass.class + ":\n" + Desc.toString(2) + "\n";
    ObjectMapper mapper = new ObjectMapper();
    JsonNode root = mapper.readTree(json.toString(2));
    String val = root.get(0).path("name").asText();
    Assert.assertEquals(debug + "port name", "output", val);
    val = root.get(0).path("type").asText();
    Assert.assertEquals(debug + "port type", "java.util.Map", val);
    val = root.get(0).path("typeArgs").get(0).path("type").asText();
    Assert.assertEquals(debug + "map key type", "java.lang.String", val);
    val = root.get(0).path("typeArgs").get(1).path("type").asText();
    Assert.assertEquals(debug + "map value type", "java.lang.Object", val);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 63 with JsonNode

use of org.codehaus.jackson.JsonNode in project apex-core by apache.

the class TypeDiscoveryTest method testTypeDiscovery.

@Test
public void testTypeDiscovery() throws Exception {
    String[] classFilePath = OperatorDiscoveryTest.getClassFileInClasspath();
    OperatorDiscoverer od = new OperatorDiscoverer(classFilePath);
    od.buildTypeGraph();
    JSONObject Desc = od.describeClassByASM(ExtendsParameterizedOperator.class.getName());
    JSONArray json = Desc.getJSONArray("portTypeInfo");
    String debug = "\n(ASM)type info for " + ExtendsParameterizedOperator.class + ":\n" + Desc.toString(2) + "\n";
    ObjectMapper mapper = new ObjectMapper();
    //List<?> l = mapper.convertValue(json, List.class);
    JsonNode root = mapper.readTree(json.toString(2));
    String val = root.get(0).path("name").asText();
    Assert.assertEquals(debug + "port name", "inputT1", val);
    val = root.get(3).path("name").asText();
    Assert.assertEquals(debug + "port name", "outportString", val);
    val = root.get(3).path("type").asText();
    Assert.assertEquals(debug + "outportList type", "java.lang.String", val);
    val = root.get(4).path("name").asText();
    Assert.assertEquals(debug + "port name", "outportList", val);
    val = root.get(4).path("type").asText();
    Assert.assertEquals(debug + "outportList type", "java.util.List", val);
    val = root.get(4).path("typeArgs").get(0).path("type").asText();
    Assert.assertEquals(debug + "outportList type", "java.lang.Number", val);
    val = root.get(5).path("name").asText();
    Assert.assertEquals(debug + "port name", "outClassObject", val);
    val = root.get(5).path("type").asText();
    Assert.assertEquals(debug + "outportList type", "com.datatorrent.stram.webapp.TypeDiscoveryTest$B", val);
    val = root.get(5).path("typeArgs").get(0).path("type").asText();
    Assert.assertEquals(debug + "outportList type", "java.lang.Number", val);
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 64 with JsonNode

use of org.codehaus.jackson.JsonNode in project exhibitor by soabase.

the class ConfigResource method parseToConfig.

private InstanceConfig parseToConfig(String newConfigJson) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    final JsonNode tree = mapper.readTree(mapper.getJsonFactory().createJsonParser(newConfigJson));
    String backupExtraValue = "";
    if (tree.get("backupExtra") != null) {
        List<EncodedConfigParser.FieldValue> values = Lists.newArrayList();
        JsonNode backupExtra = tree.get("backupExtra");
        Iterator<String> fieldNames = backupExtra.getFieldNames();
        while (fieldNames.hasNext()) {
            String name = fieldNames.next();
            String value = backupExtra.get(name).getTextValue();
            values.add(new EncodedConfigParser.FieldValue(name, value));
        }
        backupExtraValue = new EncodedConfigParser(values).toEncoded();
    }
    List<EncodedConfigParser.FieldValue> zooCfgValues = Lists.newArrayList();
    JsonNode zooCfgExtra = tree.get("zooCfgExtra");
    Iterator<String> fieldNames = zooCfgExtra.getFieldNames();
    while (fieldNames.hasNext()) {
        String name = fieldNames.next();
        String value = zooCfgExtra.get(name).getTextValue();
        zooCfgValues.add(new EncodedConfigParser.FieldValue(name, value));
    }
    final String zooCfgExtraValue = new EncodedConfigParser(zooCfgValues).toEncoded();
    final String finalBackupExtraValue = backupExtraValue;
    return new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case BACKUP_EXTRA:
                    {
                        return finalBackupExtraValue;
                    }
                case ZOO_CFG_EXTRA:
                    {
                        return zooCfgExtraValue;
                    }
                default:
                    {
                        // NOP
                        break;
                    }
            }
            JsonNode node = tree.get(fixName(config));
            if (node == null) {
                return "";
            }
            return node.asText();
        }

        @Override
        public int getInt(IntConfigs config) {
            JsonNode node = tree.get(fixName(config));
            if (node == null) {
                return 0;
            }
            return node.asInt();
        }
    };
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) JsonNode(org.codehaus.jackson.JsonNode) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 65 with JsonNode

use of org.codehaus.jackson.JsonNode in project oxTrust by GluuFederation.

the class SchemaTypeFidoDeviceSerializer method serialize.

@Override
public void serialize(FidoDevice fidoDevice, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
    log.info(" serialize() ");
    try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
        JsonNode rootNode = mapper.convertValue(fidoDevice, JsonNode.class);
        Iterator<Map.Entry<String, JsonNode>> iterator = rootNode.getFields();
        while (iterator.hasNext()) {
            Map.Entry<String, JsonNode> rootNodeEntry = iterator.next();
            if (!rootNodeEntry.getKey().equalsIgnoreCase("meta") && !rootNodeEntry.getKey().equalsIgnoreCase("externalId")) {
                AttributeHolder attributeHolder = new AttributeHolder();
                attributeHolder.setName(rootNodeEntry.getKey());
                if (rootNodeEntry.getValue().isBoolean()) {
                    attributeHolder.setType("boolean");
                } else {
                    attributeHolder.setType("string");
                }
                if (rootNodeEntry.getKey().equalsIgnoreCase("userId")) {
                    attributeHolder.setDescription("User ID that owns the device. Using this in a query filter is not supported.");
                } else if (rootNodeEntry.getKey().equalsIgnoreCase("schemas")) {
                    attributeHolder.setDescription("schemas list");
                } else {
                    attributeHolder.setDescription(rootNodeEntry.getKey());
                }
                if (rootNodeEntry.getKey().equalsIgnoreCase("id") || rootNodeEntry.getKey().equalsIgnoreCase("schemas") || rootNodeEntry.getKey().equalsIgnoreCase("userId")) {
                    attributeHolder.setUniqueness("server");
                    attributeHolder.setReturned("always");
                    attributeHolder.setCaseExact(Boolean.TRUE);
                }
                if (rootNodeEntry.getKey().equalsIgnoreCase("displayName")) {
                    attributeHolder.setReturned("always");
                }
                if (!rootNodeEntry.getKey().equalsIgnoreCase("displayName") && !rootNodeEntry.getKey().equalsIgnoreCase("description")) {
                    attributeHolder.setMutability("readOnly");
                }
                attributeHolders.add(attributeHolder);
            }
        }
        FidoDeviceCoreSchema fidoDeviceCoreSchema = (FidoDeviceCoreSchema) schemaType;
        fidoDeviceCoreSchema.setAttributeHolders(attributeHolders);
        schemaType = fidoDeviceCoreSchema;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException("Unexpected processing error; please check the FidoDevice class structure.");
    }
}
Also used : AttributeHolder(org.gluu.oxtrust.model.scim2.schema.AttributeHolder) FidoDeviceCoreSchema(org.gluu.oxtrust.model.scim2.schema.core.fido.FidoDeviceCoreSchema) JsonNode(org.codehaus.jackson.JsonNode) IOException(java.io.IOException) Map(java.util.Map) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) IOException(java.io.IOException)

Aggregations

JsonNode (org.codehaus.jackson.JsonNode)200 Test (org.junit.Test)55 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)50 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 HTTP (org.neo4j.test.server.HTTP)18 Resource (com.netflix.simianarmy.Resource)17 AWSResource (com.netflix.simianarmy.aws.AWSResource)17 ObjectNode (org.codehaus.jackson.node.ObjectNode)15 Response (org.neo4j.test.server.HTTP.Response)12 Map (java.util.Map)9 ArrayNode (org.codehaus.jackson.node.ArrayNode)9 RpcException (cz.metacentrum.perun.core.api.exceptions.RpcException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 JsonParseException (org.neo4j.server.rest.domain.JsonParseException)7 Date (java.util.Date)6 List (java.util.List)6 Description (org.hamcrest.Description)6 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)6