private void prepare(Map<String, OpsGroup> map, JsonObject swagger) { JsonArray tags = swagger.getArray(TAGS); if(null == tags || tags.isEmpty()) { map.put(DEFAULT, new OpsGroup(DEFAULT)); }else { tags.forEach(tag -> { OpsGroup group = new OpsGroup(tag.asJsonObject());; map.put(group.getName(), group); }); } }
/** * Invokes the given function for every item of array. * * <p/> * Do nothing if the array not exists or empty item. */ public void getArray(String key, Consumer<JsonValue> func) { JsonArray a = getArray(key); if(null == a) { return; } a.forEach(func); }
@Override public void parseJson(JsonValue value) { JsonObject o = value.asJsonObject(); this.name = o.getString("name"); this.unique = o.getBoolean("unique",false); JsonArray columns = o.getArray("columnNames"); if(null != columns){ for(int i=0;i<columns.length();i++){ addColumnName(columns.getString(i)); } } } }
@Override protected Object readInternal(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { try(InputStream is = inputMessage.getBody()) { if(clazz.isArray()) { try(InputStreamReader reader = new InputStreamReader(is, getCharset(inputMessage))) { try { JsonArray a = JSON.parse(reader).asJsonArray(); Object o = Array.newInstance(clazz.getComponentType(), a.length()); for(int i=0;i<a.length();i++) { Object item = Reflection.newInstance(clazz.getComponentType()); ((JsonParsable)item).parseJson(a.getObject(i)); Array.set(o, i, item); } return o; }catch (Exception e) { throw new HttpMessageNotReadableException(e.getMessage(), e); } } }else { Object o = Reflection.newInstance(clazz); try { ((JsonParsable)o).parseJson(IO.readString(is, getCharset(inputMessage))); return o; }catch (Exception e) { throw new HttpMessageNotReadableException(e.getMessage(), e); } } } }
public Long getLong(int i){ return get(i); }
/** * Wraps the property value as {@link JsonArray}. */ public JsonArray getArray(String key){ List list = get(key); return null == list ? null : new JsonArray(list); }
private List<String> tags(JsonObject op) { List<String> tagNames; JsonArray tags = op.getArray(TAGS); if(null != tags) { tagNames = tags.asList(); }else { tagNames = new ArrayList<>(); } if(tagNames.isEmpty()) { tagNames.add(DEFAULT); } return tagNames; }
@Override public Object read(Type type, Class contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { if(type instanceof Class<?>) { return readInternal((Class)type, inputMessage); }else { ParameterizedType parameterizedType = (ParameterizedType)type; Class typeArgument = (Class)parameterizedType.getActualTypeArguments()[0]; Collection c = newCollection((Class)parameterizedType.getRawType()); try(InputStream is = inputMessage.getBody()) { try(InputStreamReader reader = new InputStreamReader(is, getCharset(inputMessage))) { try { JsonArray a = JSON.parse(reader).asJsonArray(); a.forEach(item -> { if(null == item) { c.add(null); }else { Object o = Reflection.newInstance(typeArgument); ((JsonParsable)o).parseJson(item); c.add(o); } }); }catch (Exception e) { throw new HttpMessageNotReadableException(e.getMessage(), e); } } } return c; } }
public Float getFloat(int i){ return get(i); }
/** * Returns the implementation of {@link JsonValue} according to the type of given object. */ static JsonValue of(Object raw) { if(null == raw) { return NULL; } if(raw instanceof JsonValue){ return (JsonValue)raw; } if(raw instanceof Map) { return new JsonObject((Map)raw); } if(raw instanceof List) { return new JsonArray((List)raw); } return new JsonScalar(raw); }
if(null != required) { JsonObject props = definition.getObject(PROPERTIES); List<String> names = required.asList(); for(String name : names) { JsonObject prop = props.getObject(name);
public Boolean getBoolean(int i){ return get(i); }
public Double getDouble(int i){ return get(i); }
public String getString(int i){ return get(i); }
public Integer getInteger(int i){ return get(i); }
public JsonValue getValue(int i){ Object o = get(i); return null == o ? null : JsonValue.of(o); }
public JsonObject getObject(int i){ Map map = get(i); return null == map ? null : new JsonObject(map); }
public <T> T get(int i,Class<T> type){ return Converts.convert(get(i), type); }