Java Code Examples for javax.json.JsonValue#TRUE
The following examples show how to use
javax.json.JsonValue#TRUE .
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: PropertyGroup.java From FHIR with Apache License 2.0 | 6 votes |
/** * Returns the value of the specified boolean property. If not found, then * 'defaultValue' is returned instead. * @param propertyName the name of the property to retrieve */ public Boolean getBooleanProperty(String propertyName, Boolean defaultValue) { Boolean result = defaultValue; JsonValue jsonValue = getJsonValue(propertyName); if (jsonValue != null) { // If the value is stored in the JSON object as a boolean, then // construct the result from that. if (jsonValue == JsonValue.TRUE || jsonValue == JsonValue.FALSE) { result = Boolean.valueOf(jsonValue == JsonValue.TRUE); } // Otherwise, if the value was actually a string (i.e. "true" or "false"), // then construct the boolean result from the string. else if (jsonValue instanceof JsonString) { result = Boolean.valueOf(((JsonString) jsonValue).getString()); } else { throw new IllegalArgumentException("Property '" + propertyName + "' must be of type boolean or String"); } } return result; }
Example 2
Source File: JwtClaimsBuilderImpl.java From smallrye-jwt with Apache License 2.0 | 6 votes |
private static Object convertJsonValue(JsonValue jsonValue) { if (jsonValue instanceof JsonString) { String jsonString = jsonValue.toString(); return jsonString.toString().substring(1, jsonString.length() - 1); } else if (jsonValue instanceof JsonNumber) { JsonNumber jsonNumber = (JsonNumber) jsonValue; if (jsonNumber.isIntegral()) { return jsonNumber.longValue(); } else { return jsonNumber.doubleValue(); } } else if (jsonValue == JsonValue.TRUE) { return true; } else if (jsonValue == JsonValue.FALSE) { return false; } else { return null; } }
Example 3
Source File: JsonUtilsTests.java From smallrye-jwt with Apache License 2.0 | 5 votes |
@Test public void testWrapClaimValueJsonValue() { JsonValue expResult = JsonValue.TRUE; JsonValue result = JsonUtils.wrapValue(expResult); assertEquals(expResult, result); }
Example 4
Source File: PayloadMapper.java From component-runtime with Apache License 2.0 | 5 votes |
private JsonValue onArrayPrimitive(final ParameterMeta itemDef, final ArrayEntry e) { final String value = e.entry.getValue(); switch (itemDef.getType()) { case BOOLEAN: return Boolean.parseBoolean(value.trim()) ? JsonValue.TRUE : JsonValue.FALSE; case NUMBER: final Double number = Double.valueOf(value.trim()); return number == number.longValue() ? jsonp.createValue(number.longValue()) : jsonp.createValue(number); case ENUM: case STRING: return jsonp.createValue(value); default: throw new IllegalArgumentException("Unsupported structure in " + "array: " + itemDef.getType()); } }
Example 5
Source File: DataValueJsonValue.java From tcases with MIT License | 5 votes |
public void visit( BooleanValue data) { json_ = data.getValue().equals( Boolean.TRUE) ? JsonValue.TRUE : JsonValue.FALSE; }
Example 6
Source File: RequestCaseJson.java From tcases with MIT License | 5 votes |
public void visit( BooleanValue data) { json_ = data.getValue().equals( Boolean.TRUE) ? JsonValue.TRUE : JsonValue.FALSE; }
Example 7
Source File: JWTCallerPrincipal.java From tomee with Apache License 2.0 | 5 votes |
private JsonValue wrapValue(final Object value) { JsonValue jsonValue = null; if (value instanceof Number) { final Number number = (Number) value; if ((number instanceof Long) || (number instanceof Integer)) { jsonValue = Json.createObjectBuilder() .add("tmp", number.longValue()) .build() .getJsonNumber("tmp"); } else { jsonValue = Json.createObjectBuilder() .add("tmp", number.doubleValue()) .build() .getJsonNumber("tmp"); } } else if (value instanceof Boolean) { final Boolean flag = (Boolean) value; jsonValue = flag ? JsonValue.TRUE : JsonValue.FALSE; } else if (value instanceof List) { final JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); final List list = (List) value; for (Object element : list) { if (element instanceof String) { arrayBuilder.add(element.toString()); } else { JsonValue jvalue = wrapValue(element); arrayBuilder.add(jvalue); } } jsonValue = arrayBuilder.build(); } return jsonValue; }
Example 8
Source File: JsonUtils.java From smallrye-jwt with Apache License 2.0 | 4 votes |
/** * Manual converter to convert Json type to supported Java types in the spec. */ public static Object convert(final Class<?> klass, final Object value) { if (klass == null) { return value; } if (klass.isAssignableFrom(String.class) && value instanceof JsonString) { return value.toString(); } // We dont convert String to JsonString in io.smallrye.jwt.auth.principal.DefaultJWTCallerPrincipal.fixJoseTypes if (klass.isAssignableFrom(JsonString.class) && value instanceof String) { return JsonUtils.wrapValue(value); } if (klass.isAssignableFrom(Long.class) && value instanceof JsonNumber) { return ((JsonNumber) value).longValue(); } if (klass.isAssignableFrom(Boolean.class)) { if (value == JsonValue.TRUE) { return Boolean.TRUE; } if (value == JsonValue.FALSE) { return Boolean.FALSE; } if (value instanceof JsonString) { return Boolean.valueOf(value.toString()); } } if (klass.isAssignableFrom(Set.class) && value instanceof JsonArray) { return new HashSet<>(((JsonArray) value).getValuesAs(jsonValue -> { if (jsonValue instanceof JsonString) { return ((JsonString) jsonValue).getString(); } return jsonValue.toString(); })); } return value; }
Example 9
Source File: JsonpRuntime.java From jmespath-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public JsonValue createBoolean(boolean b) { return b ? JsonValue.TRUE : JsonValue.FALSE; }
Example 10
Source File: JsonStructureEndpointTest.java From openwebbeans-meecrowave with Apache License 2.0 | 4 votes |
@GET @Path("value") public JsonValue value() { return JsonValue.TRUE; }
Example 11
Source File: JsonUtil.java From activemq-artemis with Apache License 2.0 | 4 votes |
public static Object convertJsonValue(Object jsonValue, Class desiredType) { if (jsonValue instanceof JsonNumber) { JsonNumber number = (JsonNumber) jsonValue; if (desiredType == null || desiredType == Long.class || desiredType == Long.TYPE) { return number.longValue(); } else if (desiredType == Integer.class || desiredType == Integer.TYPE) { return number.intValue(); } else if (desiredType == Double.class || desiredType == Double.TYPE) { return number.doubleValue(); } else { return number.longValue(); } } else if (jsonValue instanceof JsonString) { return ((JsonString) jsonValue).getString(); } else if (jsonValue instanceof JsonValue) { if (jsonValue == JsonValue.TRUE) { return true; } else if (jsonValue == JsonValue.FALSE) { return false; } else { return jsonValue.toString(); } } else if (jsonValue instanceof Number) { Number jsonNumber = (Number) jsonValue; if (desiredType == Integer.TYPE || desiredType == Integer.class) { return jsonNumber.intValue(); } else if (desiredType == Long.TYPE || desiredType == Long.class) { return jsonNumber.longValue(); } else if (desiredType == Double.TYPE || desiredType == Double.class) { return jsonNumber.doubleValue(); } else if (desiredType == Short.TYPE || desiredType == Short.class) { return jsonNumber.shortValue(); } else { return jsonValue; } } else if (jsonValue instanceof Object[]) { Object[] array = (Object[]) jsonValue; Object[] result; if (desiredType != null) { result = (Object[]) Array.newInstance(desiredType, array.length); } else { result = array; } for (int i = 0; i < array.length; i++) { result[i] = convertJsonValue(array[i], desiredType); } return result; } else { return jsonValue; } }
Example 12
Source File: BooleanTypeInfoProducer.java From jsonix-schema-compiler with BSD 2-Clause "Simplified" License | 4 votes |
@Override public JsonValue createValue(JsonSchemaMappingCompiler<T, C> mappingCompiler, String item) { return Boolean.valueOf(item) ? JsonValue.TRUE : JsonValue.FALSE; }
Example 13
Source File: ClaimBean.java From tomee with Apache License 2.0 | 4 votes |
private JsonValue wrapValue(final Object value) { JsonValue jsonValue = null; if (JsonValue.class.isInstance(value)) { // This may already be a JsonValue jsonValue = JsonValue.class.cast(value); } else if (String.class.isInstance(value)) { jsonValue = Json.createObjectBuilder() .add(TMP, value.toString()) .build() .getJsonString(TMP); } else if (Number.class.isInstance(value)) { final Number number = Number.class.cast(value); if ((Long.class.isInstance(number)) || (Integer.class.isInstance(number))) { jsonValue = Json.createObjectBuilder() .add(TMP, number.longValue()) .build() .getJsonNumber(TMP); } else { jsonValue = Json.createObjectBuilder() .add(TMP, number.doubleValue()) .build() .getJsonNumber(TMP); } } else if (Boolean.class.isInstance(value)) { final Boolean flag = Boolean.class.cast(value); jsonValue = flag ? JsonValue.TRUE : JsonValue.FALSE; } else if (Collection.class.isInstance(value)) { final JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); final Collection list = Collection.class.cast(value); for (Object element : list) { if (String.class.isInstance(element)) { arrayBuilder.add(element.toString()); } else { final JsonValue jvalue = wrapValue(element); arrayBuilder.add(jvalue); } } jsonValue = arrayBuilder.build(); } else if (Map.class.isInstance(value)) { jsonValue = jsonb.fromJson(jsonb.toJson(value), JsonObject.class); } return jsonValue; }