/** * Parse the response content as json and decodes to map. */ default Map<String,Object> decodeJsonMap() { return JSON.decodeMap(getContent()); }
/** * Parse the json string and converts the raw value to the target type * @since 0.5.0b */ public static <T> Map<String, T> decodeMap(String json, Class<? extends T> valueType){ Map<String, Object> map = decodeMap(json); for(Map.Entry<String, Object> entry : map.entrySet()){ entry.setValue(Converts.convert(entry.getValue(),valueType, null, convertContext)); } return (Map<String, T>) map; }
protected final <T extends MetaObj> T decodeJsonStr(String json, Class<T> type) { return decodeJsonMap(JSON.decodeMap(json), type); }
protected void readInclude(Resource resource, Map<String, Object> root, String incPath) { try { Resource incRes = resource.createRelative(incPath); if (!incRes.exists()) { throw new IllegalStateException("The included file '" + incPath + "' not found"); } root.putAll(JSON.decodeMap(incRes.getContent())); }catch (IOException e){ throw new UncheckedIOException("Err read include '" + incPath + "', " + e.getMessage(), e); } }
public SwaggerDoc(String dir) { this.dir = leap.lang.path.Paths.suffixWithSlash(dir); Map map = null; File swaggerFile = Paths.get(dir).resolve("./swagger.json").toFile(); if(swaggerFile.exists()) { map = JSON.decodeMap(IO.readString(swaggerFile, Charsets.UTF_8)); }else { swaggerFile = Paths.get(dir).resolve("./swagger.yaml").toFile(); if(swaggerFile.exists()) { map = YAML.decode(Resources.createFileResource(swaggerFile).getContent()); } } if(null != map) { this.swagger = JsonObject.of(map); } }
private List<KV> flat(){ List<KV> flat = new ArrayList<>(); list.forEach(kv -> { String key = kv.key; Object value = kv.value; if(value == null || Beans.isSimpleProperty(value.getClass())){ flat.add(new KV(key,value)); }else { JsonObject json = JsonObject.of(JSON.decodeMap(JSON.encode(value))); addFlatList(key,json,flat); } }); return flat; }
return val; } else if (rawType.isAssignableFrom(Map.class)) { Map<String, Object> val = JSON.decodeMap(jsonStr, (Class<?>) actualTypes[0]); return (T) val; } else {
public void read(Map<String,MetaFormat> formats, Resource resource) { Map<String, Object> map = JSON.decodeMap(resource.getContent()); map.forEach((k,v) -> { MetaFormat f = formats.get(k.toLowerCase()); if(null != f) { throw new IllegalStateException("Found duplicated format at [" + f.getSource() + ", " + resource.getURLString() + "]"); } f = Converts.convert(v, MetaFormat.class); if(Strings.isEmpty(f.getName())) { f.setName(k); } validator.validate(f); formats.put(k.toLowerCase(), f); }); }
private static void read(PlaceholderResolver pr, Map<String,String> all, String prefix, String profile, Resource resource, Predicate<String> filter) { Map<String, Object> map = Utils.readAndGet(resource, (file) -> JSON.decodeMap(file.getContent())); Map<String, String> props = toProperties(map, prefix);
public void read(MetaApi api, Resource resource) { String content = resource.getContent(); if (Strings.isEmpty(content)) { return; } Map<String, Object> map = JSON.decodeMap(content); map.forEach((k, o) -> { if (!(o instanceof Map)) { throw new IllegalStateException("Invalid filters '" + k + "'"); } MetaQueryFilterSet qfs; Map m = (Map) o; if (m.containsKey("filters")) { qfs = Converts.convert(o, MetaQueryFilterSet.class); } else { qfs = Converts.convert(New.hashMap("filters", m), MetaQueryFilterSet.class); } if (Strings.isEmpty(qfs.getName())) { qfs.setName(k); } processFilterSet(qfs); api.addFilterSet(qfs); }); }
public void read(MetaApi api, Resource resource) { String content = resource.getContent(); if(Strings.isEmpty(content)) { return; } Map<String, Object> map = JSON.decodeMap(resource.getContent()); map.forEach((k,v) -> { MetaPermission p = api.getPermissions().get(k); if(null != p) { throw new IllegalStateException("Found duplicated permission at [" + p.getSource() + ", " + resource.getURLString() + "]"); } p = Converts.convert(v, MetaPermission.class); if(Strings.isEmpty(p.getName())) { p.setName(k); } validator.validate(p); withSource(p, resource); api.addPermission(p); }); }
private Map data(JsonObject swagger) { Map data = JSON.decodeMap(swagger.toString()); swagger = JsonObject.of(data);
String main = (String) JSON.decodeMap(pkg.getContent()).get("main"); if(!Strings.isEmpty(main)) { return createRelative(dir, main, possiblePaths);