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() };
}
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);
}
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);
}
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();
}
};
}
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.");
}
}
Aggregations