Convert a JSON routing object into the corresponding java Routing implementation.

@param o the JSON object to convert
@throws JSONConverterException if the Routing implementation is not known
501978
public Routing routingFromJSON(Model mo, JSONObject o) throws JSONConverterException {

        String type = requiredString(o, "type");
        RoutingConverter<? extends Routing> c = json2java.get(type);
        if (c == null) {
            throw new JSONConverterException("No converter available for a routing of type '" + type + "'");
        }
        return c.fromJSON(mo, o);
    }
1033796
public List<Action> listFromJSON(JSONArray in) throws JSONConverterException {
        List<Action> 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(fromJSON((JSONObject) o));
        }
        return l;
    }
976680
public static void saveJson(File json, Object object) throws IOException {
        objectMapper.writer().writeValue(json, object);
    }
102019
protected byte[] jsonSerialize(Object o) {
        byte[] res = null;
        try {
            res = JsonUtils.toJson(o).getBytes("utf-8");
        } catch (UnsupportedEncodingException e) {
            logger.error("JsonSerialize object fail ", e);
        }
        return res;
    }
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;
    }
16973
@SuppressWarnings({ "rawtypes", "unchecked" })
    private void writeJSON(Object value) throws JSONException {
        if (JSONObject.NULL.equals(value)) {
            write(zipNull, 3);
        } else if (Boolean.FALSE.equals(value)) {
            write(zipFalse, 3);
        } else if (Boolean.TRUE.equals(value)) {
            write(zipTrue, 3);
        } else {
            if (value instanceof Map) {
                value = new JSONObject((Map) value);
            } else if (value instanceof Collection) {
                value = new JSONArray((Collection) value);
            } else if (value.getClass().isArray()) {
                value = new JSONArray(value);
            }
            if (value instanceof JSONObject) {
                write((JSONObject) value);
            } else if (value instanceof JSONArray) {
                write((JSONArray) value);
            } else {
                throw new JSONException("Unrecognized object");
            }
        }
    }
198171
public static void serializeAsStream(Object o, OutputStream s) throws IOException {
        try {
            JsonStructure builtJsonObject = findFieldsToSerialize(o).mainObject;
            Map<String, Object> config = new HashMap<String, Object>();
            config.put(JsonGenerator.PRETTY_PRINTING, true);
            JsonWriterFactory writerFactory = Json.createWriterFactory(config);
            JsonWriter streamWriter = writerFactory.createWriter(s);
            streamWriter.write(builtJsonObject);
        } catch (IllegalStateException ise) {
            // the reflective attempt to build the object failed.
            throw new IOException("Unable to build JSON for Object", ise);
        } catch (JsonException e) {
            throw new IOException("Unable to build JSON for Object", e);
        }
    }
3459
private static void addFieldToJsonObject(Method getter, Object o,
                                             String fieldName, JsonObjectBuilder j) {
        try {
            Object fieldValue = getter.invoke(o);

            if (fieldValue == null) {
            } else if (fieldValue instanceof String) {
                j.add(fieldName, (String) fieldValue);
            } else if (fieldValue instanceof Boolean) {
                j.add(fieldName, (Boolean) fieldValue);
            } else if (fieldValue instanceof BigInteger) {
                j.add(fieldName, (BigInteger) fieldValue);
            } else if (fieldValue instanceof java.math.BigDecimal) {
                j.add(fieldName, (BigDecimal) fieldValue);
            } else if (fieldValue instanceof Double) {
                j.add(fieldName, (Double) fieldValue);
            } else if (fieldValue instanceof Integer) {
                j.add(fieldName, (Integer) fieldValue);
            } else if (fieldValue instanceof Long) {
                j.add(fieldName, (Long) fieldValue);
            } else if (fieldValue instanceof Short) {
                j.add(fieldName, (Short) fieldValue);
            } else if (fieldValue instanceof Byte) {
                j.add(fieldName, (Byte) fieldValue);

            } else if (fieldValue instanceof Enum) {
                try {
                    // enums need careful handling.. look for get/set Value to use.
                    Method getValueForEnumMethod = fieldValue.getClass().getMethod("getValue");
                    Object valueFromGetValueMethod = getValueForEnumMethod.invoke(fieldValue);
                    j.add(fieldName, valueFromGetValueMethod.toString());
                } catch (NoSuchMethodException e) {
                    // else fallback to toString
                    j.add(fieldName, fieldValue.toString());
                }
            } else if (fieldValue instanceof Collection
                       || fieldValue.getClass().getName().startsWith(DATA_MODEL_PACKAGE)) {
                JSONArtrifactPair fieldObjects = findFieldsToSerialize(fieldValue);
                j.add(fieldName, fieldObjects.mainObject);
                if (fieldObjects.incompatibleFieldsObject != null && !fieldObjects.incompatibleFieldsObject.isEmpty()) {
                    // As per the contract on the HasBreakingChanges interface store incompatible fields in a second object
                    j.add(fieldName + "2", fieldObjects.incompatibleFieldsObject);
                }
            } else if (fieldValue instanceof Calendar) {
                Date date = ((Calendar) fieldValue).getTime();
                j.add(fieldName, getDateFormat().format(date));
            } else if (fieldValue instanceof Date) {
                j.add(fieldName, getDateFormat().format((Date) fieldValue));
            } else if (fieldValue instanceof Locale) {
                //note that Locale toString is a bit fiddly to round trip, but it's the best we have for now.
                String localeString = ((Locale) fieldValue).toString();
                j.add(fieldName, localeString);
            } else {
                throw new IllegalStateException("Data Model Error: Unknown data model entity "
                                                + getter.getName() + " of type " + fieldValue.getClass().getName() + " on "
                                                + o.getClass().getName());
            }

        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        } catch (IllegalArgumentException e) {
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        } catch (InvocationTargetException e) {
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        } catch (JsonException e) {
            // Shouldn't happen unless field name is null or the value cannot be converted
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        }
    }
1239101
public void consume(String json) throws JsonParseException, IOException {
		if (ApitraryOrmConfiguration.showJson()) {
			showJson(json);
		}

		JsonFactory f = new JsonFactory();
		JsonParser jp = f.createJsonParser(json);

		JsonToken token = jp.nextToken();
		String fieldName = jp.getCurrentName();
		while (!(token == null && fieldName == null)) {
			on(token, fieldName, jp);

			token = jp.nextToken();
			fieldName = jp.getCurrentName();
		}
	}
1117468
String serialize(Object o) {
        String body;
        try {
            body = new String(JsonSerializer.serialize(o));
        } catch (IOException e) {
            throw new ServiceException(ErrorCode.HTTP_CLIENT_ERROR,
                    ErrorCode.HTTP_CLIENT_ERROR.getMessageTemplate(),
                    "serialize failed.");
        }
        return body;
    }
836421
public Switch switchFromJSON(JSONObject o) throws JSONConverterException {
        return new Switch(requiredInt(o, "id"), readCapacity(o));
    }
1234249
private static JsonParser newJsonParserForNode(JsonNode jsonNode) throws IOException {
        JsonParser parser = new JsonFactory().createParser(jsonNode.toString());
        parser.nextToken();
        return parser;
    }
589829
@Override
    public void serialize(T o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) {
        final FetchPath pathProperties = getPathProperties(jsonGenerator);

        if (pathProperties != null) {
            jsonContext.toJson(o, jsonGenerator, pathProperties);
        } else {
            jsonContext.toJson(o, jsonGenerator);
        }
    }
1201011
@Override
    protected Object processObject(Object o) {
        if (o instanceof PGobject &&
                        ((PGobject)o).getType().equals("jsonb")) {
            return ((PGobject) o).getValue();
        }
        return super.processObject(o);
    }
514955
public static void checkKeys(JSONObject o, String... keys) throws JSONConverterException {
        for (String k : keys) {
            if (!o.containsKey(k)) {
                throw new JSONConverterException("Missing key '" + k + "'");
            }
        }
    }
108575
public JSONObject getJson() throws JSONException {
        JSONObject json = create();
        json.put("path", eventMessagePattern);
        json.put("handlerClass", eventHandler);
        json.put("routing", isContentRouting ? "content" : "path");
        return json;
    }
723602
public static void json(Object obj, final String[] properties,
                            Writer writer, boolean writeClass,
                            Converter<Object, Map<String, Object>> mc) throws IOException {
        if (obj == null)
            writer.write(NULL);
        else
            json(obj, properties, new JSONWriter(writer), writeClass, mc);
    }