private Object requireJsonModule() { exports = JSON.decode(script); return exports; }
public Object parse(String s) { return JSON.parse(s); }
/** * Parse the response content as json and decodes to map. */ default Map<String,Object> decodeJsonMap() { return JSON.decodeMap(getContent()); }
Type[] actualTypes = pType.getActualTypeArguments(); if (rawType.isAssignableFrom(List.class)) { Object[] arr = JSON.decodeArray(jsonStr, (Class<?>) actualTypes[0]); T val = (T) Arrays.stream(arr).collect(Collectors.toList()); return val; } else if (rawType.isAssignableFrom(Map.class)) { Map<String, Object> val = JSON.decodeMap(jsonStr, (Class<?>) actualTypes[0]); return (T) val; } else { val = JSON.decode(jsonStr, (Class<T>) targetType);
/** * Creates a {@link JsonWriter} use {@link StringBuilder} as output. */ public static JsonWriter createWriter() { return createWriter(new StringBuilder()); }
@Override public String toString() { return JSON.stringify(map); } }
@Override public Object trySerialize(FieldMapping fm, Object plain) { return JSON.encode(plain,settings); }
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; }
public MetaModel read(Resource file) { String content = file.getContent().trim(); if (content.length() == 0) { return null; } String name = Strings.upperFirst(Paths.getFileNameWithoutExtension(file.getFilename())); JsonObject o = JSON.parse(file.getContent()).asJsonObject(); if(o.asMap().isEmpty()) { return null; } MetaModel model = JSON.convert(o.asMap(), MetaModel.class); if (!Strings.isEmpty(model.getClassName())) { Class<?> c = Classes.tryForName(model.getClassName()); if (null == c) { throw new IllegalStateException("Model class '" + model.getClassName() + "' not found!"); } MType type = MTypes.getMType(c); if (!type.isComplexType()) { throw new IllegalStateException("The model class '" + model.getClassName() + "' must be complex type!"); } MetaUtils.tryCopyModel(type.asComplexType(), model); } MApiModelBuilder am = nonValidateSwaggerReader.readModel(name, o.asMap(), new SwaggerTypeEx()); MetaUtils.tryCopyModel(am, model); validator.validate("Model(" + model.getName() + ")", model); return model; }
/** * Creates a {@link JsonWriter} use {@link StringBuilder} as output. */ public static JsonWriter createWriter(JsonSettings settings) { return writer().setSettings(settings).create(); }
/** * Parse the json string and converts the raw value to the target type * @since 0.5.0b */ public static <T> List<T> decodeList(String json, Class<? extends T> valueType){ T[] obj = decodeArray(json,valueType); return New.arrayList(obj); }
/** * Encodes the value to json string. */ public static String encode(Object value){ return createWriter().value(value).toString(); }
public String json(Object o) { return JSON.stringify(o); }
public String encode(Object value) { return null == value ? Strings.EMPTY : JSON.encode(value); }
/** * Creates a {@link JsonWriter} use the given {@link Appendable} as output. */ public static JsonWriter createWriter(Appendable out, JsonSettings settings) { return writer(out).setSettings(settings).create(); }
/** * Parse the response content as json and decodes to array. */ default <T> T[] decodeJsonArray(Class<T> componentType) { return JSON.decodeArray(getContent(), componentType); }
public Object decode(String s) { return JSON.decode(s); } }
/** * Returns the content of response body as {@link JsonValue}. */ default JsonValue getJson() { return JSON.parse(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; }