@SuppressWarnings({ "unchecked" })
  private static void appendJRuby(StringBuilder builder, Object object) {
    if (object == null) {
      builder.append("''");
    } else if (object instanceof List) {
      builder.append("[");

      boolean first = true;

      for (Object element : (List<Object>) object) {
        if (first) {
          first = false;
          builder.append(" ");
        } else {
          builder.append(", ");
        }

        appendJRuby(builder, element);
      }

      if (!first) {
        builder.append(" ");
      }

      builder.append("]");
    } else if (object instanceof Map) {
      builder.append("{");

      boolean first = true;

      for (Entry<String, Object> entry : ((Map<String, Object>) object).entrySet()) {
        if (first) {
          first = false;
          builder.append(" ");
        } else {
          builder.append(", ");
        }

        String key = entry.getKey();
        String escapedKey = escape(key);

        if (key.equals(escapedKey)) {
          builder.append(key);
        } else {
          builder.append("'").append(escapedKey).append("'");
        }

        builder.append(" => ");
        appendJRuby(builder, entry.getValue());
      }

      if (!first) {
        builder.append(" ");
      }

      builder.append("}");
    } else if (object instanceof byte[]) {
      String byteString = Bytes.toHex((byte[]) object);
      builder.append("'").append(escape(byteString)).append("'");
    } else {
      builder.append("'").append(escape(object)).append("'");
    }
  }
Utility class for converting objects to JRuby. It handles null, Boolean, Number, String, byte[],
List&lt;Object&gt;, Map&lt;String, Object&gt; structures.
<p>
E.g.

<pre>
Map&lt;String, Object&gt; map = new LinkedHashMap&lt;&gt;();
map.put("null", null);
map.put("boolean", true);
map.put("number", 1);
map.put("string", "str");
map.put("binary", new byte[] { 1, 2, 3 });
map.put("list", Lists.newArrayList(1, "2", true));
</pre>
</p>
<p>
Calling {@link #print(Object)} method will result:

<pre>
{ null =&gt; '', boolean =&gt; 'true', number =&gt; '1', string =&gt; 'str',
  binary =&gt; '010203', list =&gt; [ '1', '2', 'true' ] }
</pre>
</p>
hbase-common/src/main/java/org/apache/hadoop/hbase/util/JRubyFormat.java