use to return Primitive Type, or String, Or JsonObject or JsonArray
generated by a ContainerFactory
171803
public <T> T parse(InputStream in, Class<T> mapTo) throws ParseException, UnsupportedEncodingException {
		return getPBinStream().parse(in, JSONValue.defaultReader.getMapper(mapTo));
	}
543260
private static String toJSON(Object data) {
        try {
            return mapper.writeValueAsString(data);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
413141
private static Serializable jsonObjectToSerializableType(JSONObject input) {
		String type = input.optString(Apptentive.Version.KEY_TYPE, null);
		try {
			if (type != null) {
				if (type.equals(Apptentive.Version.TYPE)) {
					return new Apptentive.Version(input);
				} else if (type.equals(Apptentive.DateTime.TYPE)) {
					return new Apptentive.DateTime(input);
				}
			}
		} catch (JSONException e) {
			ApptentiveLog.e(CONVERSATION, e, "Error migrating JSONObject.");
			logException(e);
		}
		return null;
	}
1210824
@Override
    public JsonNode getJsonNode(PortletPreferences prefs, String key) throws IOException {
        final String prefValue = StringUtils.trimToNull(prefs.getValue(key, null));
        if (prefValue == null) {
            // Default to an empty object
            return mapper.createObjectNode();
        }
        return mapper.readTree(prefValue);
    }
718809
private Object instantiate(Class actualType, JSONObject j) {
        Object r = bindInterceptor.instantiate(actualType,j);
        if (r!=BindInterceptor.DEFAULT) return r;
        for (BindInterceptor bi : getWebApp().bindInterceptors) {
            r = bi.instantiate(actualType,j);
            if (r!=BindInterceptor.DEFAULT) return r;
        }

        if (actualType==JSONObject.class || actualType==JSON.class) return actualType.cast(j);

        String[] names = new ClassDescriptor(actualType).loadConstructorParamNames();

        // the actual arguments to invoke the constructor with.
        Object[] args = new Object[names.length];

        // constructor
        Constructor c = findConstructor(actualType, names.length);
        Class[] types = c.getParameterTypes();
        Type[] genTypes = c.getGenericParameterTypes();

        // convert parameters
        for( int i=0; i<names.length; i++ ) {
            try {
                args[i] = bindJSON(genTypes[i],types[i],j.get(names[i]));
            } catch (IllegalArgumentException e) {
                throw new IllegalArgumentException("Failed to convert the "+names[i]+" parameter of the constructor "+c,e);
            }
        }

        Object o = injectSetters(invokeConstructor(c, args), j, Arrays.asList(names));
        o = bindResolve(o,j);

        return o;
    }
1039629
<T> T callForJsonType(final String host, final int port, final String path,
      final List<Pair<String, String>> paramList, final Class<T> valueType) throws IOException {
    final String responseString = callForJsonString(host, port, path, paramList);
    if (null == responseString || responseString.length() == 0) {
      return null;
    }
    return new ObjectMapper().readValue(responseString, valueType);
  }
274620
private JavaType toJavaType(Type type) {
		JavaType typeToFind;
    	if (type instanceof JavaType) {
    		typeToFind = (JavaType) type;
    	} else {
    		typeToFind = _mapper.constructType(type);
    	}
		return typeToFind;
	}
337467
private JSONObject getAsJsonObject(Object pFrom) {
        JSONAware jsonVal = toJSON(pFrom);
        if (!(jsonVal instanceof JSONObject)) {
            throw new IllegalArgumentException("Expected JSON type for a TabularData is JSONObject, not " + jsonVal.getClass());
        }
        return (JSONObject) jsonVal;
    }
361492
function getSerializedType(value, descriptor) {

    if (value instanceof SerializedVariable) {
      return 'SerializedVariable';
    } else

    if (descriptor) {
      return descriptor.type;
    } else

    if (value instanceof Date) {
      return 'Date';
    } else

    if (typeof value === 'object') {
      return 'Json';
    } else

    if (typeof value === 'boolean') {
      return 'Boolean';
    } else

    if (typeof value === 'number') {
      return 'Double';
    } else {
      return 'String';
    }
  }
802248
function getDataType(obj){
	var dataType = toClass.call( obj );
	dataType = dataType.split(' ')[1];
	dataType = dataType.substring(0, dataType.length-1);

	return dataType;
}
1025796
private static Stream<IVarDef> getVarDefs( String varType, JsonObject json)
    {
    try
      {
      // Get annotations for this group of variables
      Annotated groupAnnotations = new Annotated(){};
      Optional.ofNullable( json.getJsonObject( HAS_KEY))
        .ifPresent( has -> has.keySet().stream().forEach( key -> groupAnnotations.setAnnotation( key, has.getString( key))));

      // Return variables for this variable type.
      return
        json.keySet().stream()
        .filter( key -> !key.equals( HAS_KEY))
        .map( varName -> asVarDef( varName, varType, groupAnnotations, json.getJsonObject( varName)));
      }
    catch( SystemInputException e)
      {
      throw new SystemInputException( String.format( "Error defining variables of type=%s", varType), e);
      }
    }
161592
public <T> T fromJson(@Nullable String jsonString, JavaType javaType) {
		if (StringUtils.isEmpty(jsonString)) {
			return null;
		}

		try {
			return (T) mapper.readValue(jsonString, javaType);
		} catch (IOException e) {
			logger.warn("parse json string error:" + jsonString, e);
			return null;
		}
	}
1059904
public static void convertToTypes( String serialization, String className, JsonObject newDef ) {

		JsonParser jsonParser = new JsonParser();
		JsonElement jsonTree = jsonParser.parse( serialization );

		// Creating the swagger definition
		JsonObject innerObject = new JsonObject();

		// Start adding basic properties
		innerObject.addProperty( "title", className );
		innerObject.addProperty( "definition", "" );
		innerObject.addProperty( "type", jsonTree.isJsonObject() ? "object" : jsonTree.isJsonArray() ? "array" : "string" );

		// Prevent errors with classic Swagger UI
		innerObject.addProperty( "properties", "" );

		// Inner properties
		innerObject.add( "example", jsonTree.getAsJsonObject());

		// Update our global definition
		newDef.add( "json_" + className, innerObject );
	}
724771
function (instance, instanceKey, type, json, jsonKey) {
    try {
        instance[instanceKey] = json[jsonKey];
        return [];
    }
    catch (e) {
        // tslint:disable-next-line:no-string-literal
        throw new JsonConverstionError("Property '" + instanceKey + "' of " + instance.constructor['name'] + " does not match datatype of " + jsonKey, json);
    }
}
131004
private Object readResponse(Type returnType, JsonNode jsonNode, String id) throws Throwable {
		raiseExceptionIfNotValidResponseObject(jsonNode);
		final ObjectNode jsonObject = ObjectNode.class.cast(jsonNode);
		notifyAnswerListener(jsonObject);
		handleErrorResponse(jsonObject);
		if (hasResult(jsonObject)) {
			if (isReturnTypeInvalid(returnType)) {
				return null;
			}
			return constructResponseObject(returnType, jsonObject);
		}
		return null;
	}
965053
private static JsonStructure toJson( FunctionInputDef functionInput, String varType)
    {
    JsonObjectBuilder builder = Json.createObjectBuilder();
    toStream( functionInput.getVarDefs())
      .filter( varDef -> varDef.getType().equals( varType))
      .sorted()
      .forEach( varDef -> builder.add( varDef.getName(), toJson( varDef)));

    return builder.build();
    }
1224863
void toJSONString(final Map<ReferenceEqualityKey<JSONReference>, CharSequence> jsonReferenceToId,
            final boolean includeNullValuedFields, final int depth, final int indentWidth,
            final StringBuilder buf) {
        final boolean prettyPrint = indentWidth > 0;
        final int n = items.size();
        int numDisplayedFields;
        if (includeNullValuedFields) {
            numDisplayedFields = n;
        } else {
            numDisplayedFields = 0;
            for (final Entry<String, Object> item : items) {
                if (item.getValue() != null) {
                    numDisplayedFields++;
                }
            }
        }
        if (objectId == null && numDisplayedFields == 0) {
            buf.append("{}");
        } else {
            buf.append(prettyPrint ? "{\n" : "{");
            if (objectId != null) {
                // id will be non-null if this object does not have an @Id field, but was referenced by
                // another object (need to include ID_TAG)
                if (prettyPrint) {
                    JSONUtils.indent(depth + 1, indentWidth, buf);
                }
                buf.append('"');
                buf.append(JSONUtils.ID_KEY);
                buf.append(prettyPrint ? "\": " : "\":");
                JSONSerializer.jsonValToJSONString(objectId, jsonReferenceToId, includeNullValuedFields, depth + 1,
                        indentWidth, buf);
                if (numDisplayedFields > 0) {
                    buf.append(',');
                }
                if (prettyPrint) {
                    buf.append('\n');
                }
            }
            for (int i = 0, j = 0; i < n; i++) {
                final Entry<String, Object> item = items.get(i);
                final Object val = item.getValue();
                if (val != null || includeNullValuedFields) {
                    final String key = item.getKey();
                    if (key == null) {
                        // Keys must be quoted, so the unquoted null value cannot be a key
                        // (Should not happen -- JSONParser.parseJSONObject checks for null keys)
                        throw new IllegalArgumentException("Cannot serialize JSON object with null key");
                    }
                    if (prettyPrint) {
                        JSONUtils.indent(depth + 1, indentWidth, buf);
                    }
                    buf.append('"');
                    JSONUtils.escapeJSONString(key, buf);
                    buf.append(prettyPrint ? "\": " : "\":");
                    JSONSerializer.jsonValToJSONString(val, jsonReferenceToId, includeNullValuedFields, depth + 1,
                            indentWidth, buf);
                    if (++j < numDisplayedFields) {
                        buf.append(',');
                    }
                    if (prettyPrint) {
                        buf.append('\n');
                    }
                }
            }
            if (prettyPrint) {
                JSONUtils.indent(depth, indentWidth, buf);
            }
            buf.append('}');
        }
    }