MCPcopy Create free account
hub / github.com/cmu-db/benchbase / fieldsToJSON

Method fieldsToJSON

src/main/java/com/oltpbenchmark/util/JSONUtil.java:223–251  ·  view source on GitHub ↗

For a given list of Fields, write out the contents of the corresponding field to the JSONObject The each of the JSONObject's elements will be the upper case version of the Field's name @param @param stringer @param object @param base_class @param fields @throws JSONException

(
      JSONStringer stringer, T object, Class<? extends T> base_class, Field[] fields)

Source from the content-addressed store, hash-verified

221 * @throws JSONException
222 */
223 public static <T> void fieldsToJSON(
224 JSONStringer stringer, T object, Class<? extends T> base_class, Field[] fields)
225 throws JSONException {
226 if (LOG.isDebugEnabled()) {
227 LOG.debug("Serializing out {} elements for {}", fields.length, base_class.getSimpleName());
228 }
229 for (Field f : fields) {
230 String json_key = f.getName().toUpperCase();
231 stringer.key(json_key);
232
233 try {
234 Class<?> f_class = f.getType();
235 Object f_value = f.get(object);
236
237 // Null
238 if (f_value == null) {
239 writeFieldValue(stringer, f_class, f_value);
240 // Maps
241 } else if (f_value instanceof Map) {
242 writeFieldValue(stringer, f_class, f_value);
243 // Everything else
244 } else {
245 writeFieldValue(stringer, f_class, f_value);
246 }
247 } catch (Exception ex) {
248 throw new JSONException(ex);
249 }
250 }
251 }
252
253 /**
254 * @param stringer

Callers

nothing calls this directly

Calls 4

writeFieldValueMethod · 0.95
getNameMethod · 0.65
getTypeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected