Convert a Link to a JSON object.

@param s the switch to convert
@return  the JSON object
431471
public JSONObject linkToJSON(Link s) {
        JSONObject o = new JSONObject();
        o.put("id", s.id());
        o.put(CAPACITY_LABEL, s.getCapacity());
        o.put(SWITCH_LABEL, s.getSwitch().id());
        o.put("physicalElement", physicalElementToJSON(s.getElement()));
        return o;
    }
984970
public JSONObject toJson() {
        JSONObject obj = new JSONObject().put(OBJECT_LOCATION, new JSONObject().put("lat", lat).put("lng", lng))
                .put(STRING_NAME, name).put(STRING_TYPES, new JSONArray(types));
        if (accuracy != -1)
            obj.put(INTEGER_ACCURACY, accuracy);
        if (phoneNumber != null)
            obj.put(STRING_PHONE_NUMBER, phoneNumber);
        if (address != null)
            obj.put(STRING_ADDRESS, address);
        if (website != null)
            obj.put(STRING_WEBSITE, website);
        if (locale != null)
            obj.put(STRING_LANGUAGE, locale.getLanguage());
        return obj;
    }
548419
public JSONObject toJSON() throws JSONException {
        JSONObject json = new JSONObject();

        json.put(JSON_TYPE, this.getType());

        return json;
    }
92528
public JSONObject routingToJSON(Routing routing) throws JSONConverterException {
        RoutingConverter c = java2json.get(routing.getClass());
        if (c == null) {
            throw new JSONConverterException("No converter available for a routing with the '" + routing.getClass() + "' className");
        }
        return c.toJSON(routing);

    }
441322
private static JsonNode toJson(AggregatedHttpMessage res, @Nullable JsonNodeType expectedNodeType) {
        final String content = toString(res);
        final JsonNode node;
        try {
            node = Jackson.readTree(content);
        } catch (JsonParseException e) {
            throw new CentralDogmaException("failed to parse the response JSON", e);
        }

        if (expectedNodeType != null && node.getNodeType() != expectedNodeType) {
            throw new CentralDogmaException(
                    "invalid server response; expected: " + expectedNodeType +
                    ", actual: " + node.getNodeType() + ", content: " + content);
        }
        return node;
    }
529221
private Object convertStrToObjTree(String s) {
        Object contentObj = null;
        if (s != null) {
            s = s.trim();
            try {
                if (s.startsWith("{")) {
                    contentObj = Config.getInstance().getMapper().readValue(s, new TypeReference<HashMap<String, Object>>() {
                    });
                } else if (s.startsWith("[")) {
                    contentObj = Config.getInstance().getMapper().readValue(s, new TypeReference<List<Object>>() {
                    });
                } else {
                    logger.error("cannot deserialize json str: {}", s);
                    return null;
                }
            } catch (IOException e) {
                logger.error(e.getMessage());
            }
        }
        return contentObj;
    }
691090
@JsonValue
	public Object toJsonValue() {
		if (s != null)
			return s;
		if (n != null)
			return n;
		return null;
	}
1359971
public final String toJson() {
    Gson gson = new GsonBuilder()
      .registerTypeAdapter(BoundingBox.class, new BoundingBoxTypeAdapter())
      .create();
    return gson.toJson(this, BoundingBox.class);
  }
1096536
public JsonObject toJson() {
        final JsonObjectBuilder builder = Json.createObjectBuilder();
        builder.add(EL_DATA_TYPE, dataType);
        builder.add(EL_DATA_CONTENT_TYPE, dataContentTypeStr);
        if (meta == null) {
            return builder.build();
        }
        builder.add(EL_META_TYPE, metaType);
        builder.add(EL_META_CONTENT_TYPE, metaContentTypeStr);
        if (meta instanceof JsonObject) {
            final JsonObject jo = (JsonObject) meta;
            return builder.add(metaType, jo).build();
        }
        if (meta instanceof ToJsonCapable) {
            final ToJsonCapable tjc = (ToJsonCapable) meta;
            return builder.add(metaType, tjc.toJson()).build();
        }
        if (meta instanceof Base64Data) {
            final Base64Data base64data = (Base64Data) meta;
            return builder.add(metaType, base64data.getEncoded()).build();
        }
        throw new IllegalStateException("Unknown meta object type: " + meta.getClass());
    }
449006
public static Object fromJson(String json) {
    try {
      JSONObject jsonObject = new JSONObject(json);
      if (jsonObject.has("JSON")) {
        return convert(jsonObject.get("JSON"));
      } else {
        return convert(jsonObject);
      }
    } catch (Exception e) {
      throw new RuntimeException("json=" + json, e);
    }
  }
854219
public String toJson(Object o) {
		try {
			String json = objectMapper.writeValueAsString(o);
			LOG.debug(json);
			return json;
		} catch (Exception e) {
			throw Exceptions.propagate(e);
		}
	}
852376
@SuppressWarnings("UnusedDeclaration")
  public static Bindings fromJson( String json )
  {
    try
    {
      return PARSER.get().parseJson( json );
    }
    catch( ScriptException e )
    {
      throw new RuntimeException( e );
    }
  }
400248
private static JsonStructure toJson( TupleRef tuple)
    {
    JsonObjectBuilder builder = Json.createObjectBuilder();

    toStream( tuple.getVarBindings()).forEach( binding -> builder.add( binding.getVar(), String.valueOf( binding.getValue())));
    
    return builder.build();
    }
1206471
public static S3Link fromJson(S3ClientCache s3cc, String json) {
        ID id = Jackson.fromJsonString(json, ID.class);
        return new S3Link(s3cc, id);
    }
1009126
public JSONArray linksToJSON(Collection<Link> c) {
        JSONArray a = new JSONArray();
        for (Link l : c) {
            a.add(linkToJSON(l));
        }
        return a;
    }
454973
public JSONObject toJson() {
        JSONObject ret = new JSONObject();
        ret.put("url",url);
        if (user != null) {
            ret.put("user",user);
            ret.put("password",password);
        }
        return ret;
    }
212430
public JSONObject toJSON() {
        try {
            return new JSONObject(properties).putOpt("name", getName());
        } catch (JSONException e) {
            e.printStackTrace();
            Log.e(TAG, e, "toJSON()");
            throw new RuntimeAssertion("NodeEntry.toJSON() failed for '%s'", this);
        }
    }