Convert a list of json-encoded sat-constraints.
@param mo the model to rely on
@param in the constraints to decode
@return the constraint list. Might be empty
@throws JSONConverterException if the conversion failed
431895
public List<SatConstraint> listFromJSON(Model mo, JSONArray in) throws JSONConverterException {
        List<SatConstraint> l = new ArrayList<>(in.size());
        for (Object o : in) {
            if (!(o instanceof JSONObject)) {
                throw new JSONConverterException("Expected an array of JSONObject but got an array of " + o.getClass().getName());
            }
            l.add((SatConstraint) fromJSON(mo, (JSONObject) o));
        }
        return l;
    }
376359
private static ICondition asCondition( JsonObject json)
    {
    List<Function<JsonObject,Optional<ICondition>>> converters = Arrays.asList
      (
        SystemInputJson::asContainsAll,
        SystemInputJson::asContainsAny,
        SystemInputJson::asContainsNone,
        SystemInputJson::asNot,
        SystemInputJson::asAnyOf,
        SystemInputJson::asAllOf,
        SystemInputJson::asLessThan,
        SystemInputJson::asMoreThan,
        SystemInputJson::asNotLessThan,
        SystemInputJson::asNotMoreThan,
        SystemInputJson::asBetween,
        SystemInputJson::asEquals
       );

    return
      converters.stream()
      .map( converter -> converter.apply( json))
      .filter( Optional::isPresent)
      .map( Optional::get)
      .findFirst()
      .orElseThrow( () -> new SystemInputException( String.format( "Unknown condition type: %s", json.keySet().iterator().next())))
      ;
    }
843080
@SuppressWarnings("unchecked")
  private static void getParamsFromJSON(Map<String, String> params, String json) {
    JSONParser parser = new JSONParser(json);
    try {
      Object o = ObjectBuilder.getVal(parser);
      if (!(o instanceof Map))
        return;
      Map<String, Object> map = (Map<String, Object>) o;
      // To make consistent with json.param handling, we should make query
      // params come after json params (i.e. query params should
      // appear to overwrite json params.

      // Solr params are based on String though, so we need to convert
      for (Map.Entry<String, Object> entry : map.entrySet()) {
        String key = entry.getKey();
        Object val = entry.getValue();
        if (params.get(key) != null) {
          continue;
        }
        if (val == null) {
          params.remove(key);
        } else if (val instanceof String) {
          params.put(key, (String) val);
        }
      }
    } catch (Exception e) {
      log.debug("ignore parse exceptions at this stage, they may be caused by incomplete macro expansions", e);
      return;
    }
  }
364217
private static void parseBounds(JSONObject modelJSON,
                                    Shape current) throws JSONException {
        if (modelJSON.has("bounds")) {
            JSONObject boundsObject = modelJSON.getJSONObject("bounds");
            current.setBounds(new Bounds(new Point(boundsObject.getJSONObject("lowerRight").getDouble("x"),
                                                   boundsObject.getJSONObject("lowerRight").getDouble(
                                                           "y")),
                                         new Point(boundsObject.getJSONObject("upperLeft").getDouble("x"),
                                                   boundsObject.getJSONObject("upperLeft").getDouble("y"))));
        }
    }
426721
@Override
	public Object convertJsonToJava(String jsonArg, Type paramType, Annotation[] parameterAnnotations) throws JsonUnmarshallingException, JsonMarshallerException {
		if ("null".equals(jsonArg)) {
			return null;
		}
		JsonUnmarshaller juma = getJsonUnmarshallerAnnotation(parameterAnnotations);
		if (null != juma) {
			Object result = getResult(jsonArg, argumentServices.getIJsonMarshallerInstance(juma.value()), juma.type());
			argumentServices.checkType(result, paramType);
			return result;
		} else {
			return convertArgument(jsonArg, paramType);
		}
	}
1139670
@SuppressWarnings("unchecked")
  private Map<String, Object> convertToMap(Object jsonDocument) {
    Map<String, Object> jsonMap = new LinkedHashMap<>();

    // Document is a text block
    if (!(jsonDocument instanceof JSONObject)) {
      jsonMap.put("content", jsonDocument);
      return jsonMap;
    }

    JSONObject obj = (JSONObject) jsonDocument;
    for (String key : obj.keySet()) {
      Object value = obj.get(key);

      if (value instanceof JSONObject) {
        value = convertToMap(value);
      } else if (value instanceof JSONArray) {
        ArrayList<Map<String, Object>> collection = new ArrayList<>();

        for (Object element : ((JSONArray) value)) {
          collection.add(convertToMap(element));
        }

        value = collection;
      }

      jsonMap.put(key, value);
    }
    return jsonMap;

  }
134876
@Bean
	@ConditionalOnMissingBean(name = "busJsonConverter")
	@StreamMessageConverter
	public AbstractMessageConverter busJsonConverter(
			@Autowired(required = false) ObjectMapper objectMapper) {
		return new BusJacksonMessageConverter(objectMapper);
	}
836421
public Switch switchFromJSON(JSONObject o) throws JSONConverterException {
        return new Switch(requiredInt(o, "id"), readCapacity(o));
    }
1220780
private JsonMBean extractJsonMBeanAnnotation(Object object) {
        // Try directly
        Class<?> clazz = object.getClass();
        JsonMBean anno =  clazz.getAnnotation(JsonMBean.class);
        if (anno == null && ModelMBean.class.isAssignableFrom(object.getClass())) {
            // For ModelMBean we try some heuristic to get to the managed resource
            // This works for all subclasses of RequiredModelMBean as provided by the JDK
            // but maybe for other ModelMBean classes as well
            Boolean isAccessible = null;
            Field field = null;
            try {
                field = findField(clazz, "managedResource");
                if (field != null) {
                    isAccessible = field.isAccessible();
                    field.setAccessible(true);
                    Object managedResource = field.get(object);
                    anno = managedResource.getClass().getAnnotation(JsonMBean.class);
                }
            } catch (IllegalAccessException e) {
                // Ignored silently, but we tried it at least
            } finally {
                if (isAccessible != null) {
                    field.setAccessible(isAccessible);
                }
            }
        }
        return anno;
    }
1262157
protected static <T> T parse(String in, JsonReaderI<T> mapper) {
		try {
			JSONParser p = new JSONParser(DEFAULT_PERMISSIVE_MODE);
			return p.parse(in, mapper);
		} catch (Exception e) {
			return null;
		}
	}
1102927
public static VM getVM(Model mo, int vmID) throws JSONConverterException {
        VM vm = new VM(vmID);
        if (!mo.contains(vm)) {
            throw new JSONConverterException("Undeclared vm '" + vmID + "'");
        }
        return vm;
    }
451387
@Override
  public JsonArray convertSchema(String inputSchema, WorkUnitState workUnit) throws SchemaConversionException {
    JsonParser jsonParser = new JsonParser();
    JsonElement jsonSchema = jsonParser.parse(inputSchema);
    return jsonSchema.getAsJsonArray();
  }
362982
public JSONArray toJSON(Collection<SatConstraint> e) throws JSONConverterException {
        JSONArray arr = new JSONArray();
        for (SatConstraint cstr : e) {
            arr.add(toJSON(cstr));
        }
        return arr;
    }
810726
public <V> V convertFrom(final InputStream in) {
        if (in == null) return null;
        return (V) new AnyDecoder(factory).convertFrom(new JsonStreamReader(in));
    }
9772
def _json_convert(obj, json_options=DEFAULT_JSON_OPTIONS):
    
    if hasattr(obj, 'iteritems') or hasattr(obj, 'items'):  # PY3 support
        return SON(((k, _json_convert(v, json_options))
                    for k, v in iteritems(obj)))
    elif hasattr(obj, '__iter__') and not isinstance(obj, (text_type, bytes)):
        return list((_json_convert(v, json_options) for v in obj))
    try:
        return default(obj, json_options)
    except TypeError:
        return obj
441667
private JsonElement parseEnumType(JsonSchema schema, JsonElement value)
      throws DataConversionException {
    if (schema.getSymbols().contains(value)) {
      return value;
    }
    throw new DataConversionException(
        "Invalid symbol: " + value.getAsString() + " allowed values: " + schema.getSymbols().toString());
  }
860570
public void linkFromJSON(Model mo, Network net, JSONObject o) throws JSONConverterException {
        net.connect(requiredInt(o, "id"),
                readCapacity(o),
                getSwitch(net, requiredInt(o, SWITCH_LABEL)),
                physicalElementFromJSON(mo, net, (JSONObject) o.get("physicalElement"))
        );
    }