Java Code Examples for com.eclipsesource.json.JsonValue#isString()
The following examples show how to use
com.eclipsesource.json.JsonValue#isString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BoxEntity.java From box-android-sdk with Apache License 2.0 | 6 votes |
/** * Helper method that will parse into a known child of BoxEntity. * * @param json JsonObject representing a BoxEntity or one of its known children. * @return a BoxEntity or one of its known children. */ public static BoxEntity createEntityFromJson(final JsonObject json){ JsonValue typeValue = json.get(BoxEntity.FIELD_TYPE); if (!typeValue.isString()) { return null; } String type = typeValue.asString(); BoxEntityCreator creator = ENTITY_ADDON_MAP.get(type); BoxEntity entity = null; if (creator == null){ entity = new BoxEntity(); } else { entity = creator.createEntity(); } entity.createFromJson(json); return entity; }
Example 2
Source File: BoxAuthentication.java From box-android-sdk with Apache License 2.0 | 6 votes |
/** * Load auth info from storage. * * @param context context here is only used to load shared pref. In case you don't need shared pref, you can ignore this * argument in your implementation. * @return a map of all known user authentication information with keys being userId. */ protected ConcurrentHashMap<String, BoxAuthenticationInfo> loadAuthInfoMap(Context context) { ConcurrentHashMap<String, BoxAuthenticationInfo> map = new ConcurrentHashMap<>(); String json = context.getSharedPreferences(AUTH_STORAGE_NAME, 0).getString(AUTH_MAP_STORAGE_KEY, ""); if (json.length() > 0) { BoxEntity obj = new BoxEntity(); obj.createFromJson(json); for (String key: obj.getPropertiesKeySet()) { JsonValue value = obj.getPropertyValue(key); BoxAuthenticationInfo info = null; if (value.isString()) { info = new BoxAuthenticationInfo(); info.createFromJson(value.asString()); } else if (value.isObject()){ info = new BoxAuthenticationInfo(); info.createFromJson(value.asObject()); } map.put(key, info); } } return map; }
Example 3
Source File: TagSetParser.java From dungeon with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Effectively parses the JsonValue and produces a TagSet. */ public TagSet<E> parse() { TagSet<E> tagSet = TagSet.makeEmptyTagSet(enumClass); if (jsonValue != null) { if (jsonValue.isArray()) { for (JsonValue value : jsonValue.asArray()) { if (value.isString()) { String tag = value.asString(); try { tagSet.addTag(Enum.valueOf(enumClass, tag)); } catch (IllegalArgumentException fatal) { // Guarantee that bugged resource files are not going to make it to a release. String message = "invalid tag '" + tag + "' found."; throw new InvalidTagException(message, fatal); } } else { throw new InvalidTagException("tag value is not a string."); } } } else { throw new InvalidTagException("JsonObject is neither null or an array"); } } return tagSet; }
Example 4
Source File: WebServer.java From r2cloud with Apache License 2.0 | 5 votes |
public static String getString(JsonValue value, String name) { JsonValue field = ((JsonObject) value).get(name); if (field == null || field.isNull()) { return null; } if (!field.isString()) { return null; } return field.asString(); }
Example 5
Source File: WebServer.java From r2cloud with Apache License 2.0 | 5 votes |
public static Integer getInteger(JsonValue value, String name) { JsonValue result = ((JsonObject) value).get(name); if (result == null || result.isNull()) { return null; } if (result.isString()) { return Integer.parseInt(result.asString()); } if (!result.isNumber()) { throw new NumberFormatException(); } return result.asInt(); }
Example 6
Source File: JsonConfig.java From ServerSync with GNU General Public License v3.0 | 5 votes |
private static String getString(JsonObject root, String name) throws IOException { JsonValue jsv = root.get(name); if (jsv.isNull()) { throw new IOException(String.format("No %s value present in configuration file", name)); } if (!jsv.isString()) { throw new IOException(String.format("Invalid value for %s, expected string", name)); } return jsv.asString(); }
Example 7
Source File: Metadata.java From box-java-sdk with Apache License 2.0 | 5 votes |
/** * Returns a value. * @param path the path that designates the key. Must be prefixed with a "/". * @return the metadata property value. * @deprecated Metadata#get() does not handle all possible metadata types; use Metadata#getValue() instead */ @Deprecated public String get(String path) { final JsonValue value = this.values.get(this.pathToProperty(path)); if (value == null) { return null; } if (!value.isString()) { return value.toString(); } return value.asString(); }
Example 8
Source File: RecipeJson.java From Cubes with MIT License | 5 votes |
public static ItemStack parseStack(JsonValue json) { if (json.isString()) { return new ItemStack(getItem(json.asString())); } else if (json.isObject()) { JsonObject obj = json.asObject(); JsonValue id = obj.get("id"); if (id == null) throw new JsonException("No id"); return new ItemStack(getItem(id.asString()), obj.getInt("count", 1), obj.getInt("meta", 0)); } else if (json.isNull()) { return null; } throw new JsonException("Invalid type " + json.toString()); }
Example 9
Source File: JsonCreaturePresetFactory.java From dungeon with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Attempts to read a string from the provided JSON object, returning null if the string is not present or if the * value is not a string. * * @param jsonObject a JsonObject, not null * @param name a String, not null * @return a String or null */ @Nullable private static String getStringFromJsonObject(@NotNull JsonObject jsonObject, @NotNull String name) { JsonValue value = jsonObject.get(name); if (value == null || !value.isString()) { return null; } else { return value.asString(); } }
Example 10
Source File: IrdbImporter.java From IrScrutinizer with GNU General Public License v3.0 | 4 votes |
public ProtocolDeviceSubdevice(JsonValue jprotocol, long device, long subdevice) { this(jprotocol.isString() ? jprotocol.asString() : null, device, subdevice); }
Example 11
Source File: Utils.java From Skype4J with Apache License 2.0 | 4 votes |
public static String coerceToString(JsonValue value) { return value.isString() ? value.asString() : value.toString(); }
Example 12
Source File: BlockJson.java From Cubes with MIT License | 4 votes |
@Override public String[] parse(JsonValue prop) { String[] textures = new String[6]; if (prop.isString()) { Arrays.fill(textures, prop.asString()); } else { JsonObject texture = prop.asObject(); for (JsonObject.Member member : texture) { String value = member.getValue().asString(); switch (member.getName()) { case "posX": textures[BlockFace.posX.index] = value; break; case "negX": textures[BlockFace.negX.index] = value; break; case "posY": case "top": textures[BlockFace.posY.index] = value; break; case "negY": case "bottom": textures[BlockFace.negY.index] = value; break; case "posZ": textures[BlockFace.posZ.index] = value; break; case "negZ": textures[BlockFace.negZ.index] = value; break; case "side": textures[BlockFace.posX.index] = value; textures[BlockFace.negX.index] = value; textures[BlockFace.posZ.index] = value; textures[BlockFace.negZ.index] = value; break; case "other": for (int i = 0; i < textures.length; i++) { if (textures[i] == null) textures[i] = value; } break; default: throw new JsonException("Unexpected block texture member \"" + member.getName() + "\""); } } } return textures; }
Example 13
Source File: StringJsonRule.java From dungeon with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void validate(JsonValue value) { if (!value.isString()) { throw new IllegalArgumentException(value + " is not a string."); } }