Here you can find the source of fill_key_value(JsonObjectBuilder jsonObject, String key, Object value)
private static void fill_key_value(JsonObjectBuilder jsonObject, String key, Object value)
//package com.java2s; //License from project: Open Source License import java.util.List; import java.util.Map; import javax.json.Json; import javax.json.JsonArrayBuilder; import javax.json.JsonBuilderFactory; import javax.json.JsonObjectBuilder; public class Main { private static JsonBuilderFactory jsonFactory = Json.createBuilderFactory(null); private static void fill_key_value(JsonObjectBuilder jsonObject, String key, Object value) { if (jsonObject == null || key == null) { return; }/*from w w w . java 2 s . com*/ if (value == null) { jsonObject.addNull(key); } else if (value instanceof String) { jsonObject.add(key, (String) value); } else if (value instanceof Integer) { jsonObject.add(key, ((Integer) value).intValue()); } else if (value instanceof Long) { jsonObject.add(key, ((Long) value).longValue()); } else if (value instanceof Boolean) { jsonObject.add(key, ((Boolean) value).booleanValue()); } else if (value instanceof List) { fill_list(jsonObject, key, (List<Object>) value); } else if (value instanceof Map) { JsonObjectBuilder entryObj = jsonFactory.createObjectBuilder(); fill_map(entryObj, (Map<String, Object>) value); jsonObject.add(key, entryObj); } } private static void fill_list(JsonObjectBuilder jsonObject, String key, List<Object> list) { if (jsonObject == null || key == null) { return; } JsonArrayBuilder arrayBuilder = jsonFactory.createArrayBuilder(); for (Object entry : list) { if (entry instanceof Map) { JsonObjectBuilder entryObj = jsonFactory.createObjectBuilder(); fill_map(entryObj, (Map<String, Object>) entry); arrayBuilder.add(entryObj); } } jsonObject.add(key, arrayBuilder); } private static void fill_map(JsonObjectBuilder jsonObject, Map<String, Object> map) { if (jsonObject == null) { return; } for (String key : map.keySet()) { Object value = map.get(key); fill_key_value(jsonObject, key, value); } } }