List of utility methods to do Json Create
JsonObject | build(Map map) Builds a JsonObject from an arbitrarily nested Map. JsonObjectBuilder root = Json.createObjectBuilder(); for (Object key : map.keySet()) { Object value = map.get(key); if (value == null) { root.addNull(key.toString()); } else if (value instanceof Map) { root.add(key.toString(), build((Map) value)); } else { ... |
JsonObject | buildContentResponse(String userId, String message) build Content Response JsonObjectBuilder content = Json.createObjectBuilder();
content.add(userId, message);
return content.build();
|
JsonArray | buildJsonArray(String[][] twoDimensionArray) Builds two dimensional JsonArray form String[][] JsonArrayBuilder keyboardBuilder = Json.createArrayBuilder(); for (String[] boardElement : twoDimensionArray) { JsonArrayBuilder key = Json.createArrayBuilder(); for (String keyElement : boardElement) { key.add(keyElement); keyboardBuilder.add(key.build()); return keyboardBuilder.build(); |
String | convertToJson(Object myObject) convert To Json if (myObject instanceof Map<?, ?>) { final Map<?, ?> map = (Map<?, ?>) myObject; final StringBuilder sb = new StringBuilder("{"); boolean first = true; for (final Map.Entry<?, ?> entry : map.entrySet()) { if (first) { first = false; } else { ... |
String | convertToJson(Object obj) Convert a nested Map data structure to a JSON String. return convertToJson(obj, false);
|
JsonArrayBuilder | createArrayBuilder() create Array Builder return PROVIDER.createArrayBuilder();
|
JsonArrayBuilder | createArrayBuilder() Creates a JSON array builder return createJsonProvider().createArrayBuilder();
|
JsonObjectBuilder | createJsonFrom(JsonObject user, String... ignoreKeys) create Json From JsonObjectBuilder builder = Json.createObjectBuilder(); List<String> doNotCopy = Arrays.asList(ignoreKeys); for (Map.Entry<String, JsonValue> entry : user.entrySet()) { if (!!!doNotCopy.contains(entry.getKey())) { builder.add(entry.getKey(), entry.getValue()); return builder; ... |
JsonValue | createJsonValue(String string) Create a JsonValue using a String return Json.createObjectBuilder().add("value", string).build().getJsonString("value"); |
JsonWriterFactory | createPrettyWriterFactory() create Pretty Writer Factory HashMap<String, Object> prettyConfigMap = new HashMap<String, Object>(); prettyConfigMap.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE); JsonWriterFactory prettyWriterFactory = Json.createWriterFactory(prettyConfigMap); return prettyWriterFactory; |