List of utility methods to do Json
String | jsonValueToJsonString(final JsonValue jsonValue, final String key) Parse a JsonValue into String final StringBuilder builder = new StringBuilder(); if (key != null) { builder.append('\"').append(key).append("\":"); if (jsonValue instanceof JsonString) { builder.append('\"').append(jsonValue.toString()).append('\"'); } else if (jsonValue instanceof JsonNumber || jsonValue instanceof JsonObject) { builder.append(jsonValue.toString()); ... |
JsonArray | listToJsonArray(List Method used to build the JSON Array of Strings. JsonArrayBuilder ab = Json.createArrayBuilder(); for (String element : list) { ab.add(element); return ab.build(); |
JsonObjectBuilder | mapToJsonObjectBuilder(Map map To Json Object Builder JsonObjectBuilder jsonObject = Json.createObjectBuilder(); if (map == null || map.isEmpty()) { return jsonObject; Iterator<Entry<String, String>> i = map.entrySet().iterator(); while (i.hasNext()) { Entry<String, String> e = i.next(); jsonObject.add(e.getKey(), e.getValue()); ... |
JsonObject | newObject() Creates a new object. return Json.createObjectBuilder().build();
|
JsonValue | nullable(String value) Returns a JsonValue from a String. if (value == null) { return JsonValue.NULL; return Json.createObjectBuilder().add("_", value).build().get("_"); |
String | objectToJsonDateSerializer(Object ts, final String dateformat) object To Json Date Serializer String jsonStr = null; gson = new GsonBuilder().registerTypeHierarchyAdapter(Date.class, new JsonSerializer<Date>() { public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { SimpleDateFormat format = new SimpleDateFormat(dateformat); return new JsonPrimitive(format.format(src)); }).setDateFormat(dateformat).create(); if (gson != null) { ... |
void | printJavaxJsonProvider() print Javax Json Provider System.out.println("Jsonp Provider:" + JsonProvider.provider().getClass().getCanonicalName());
System.out.println();
|
Object | read(String jsonString) read return parse(new StringCharacterIterator(jsonString)); |
Date | readMandatoryDateField(JsonParser jsonParser, String fieldName) read Mandatory Date Field String value = readMandatoryField(jsonParser, fieldName); if (value == null) { return null; return parseDateValue(value); |
boolean | requiredParams(JsonObject map, String... params) Checks if the parameters specified (which are required) are used as keys in the specified map for (String param : params) { if (!map.containsKey(param)) { return false; return true; |