public void write(Object object) throws IOException {
    if (object == null) {
      out.write("null");
    } else if (object instanceof Number) {
      writeNumber((Number) object);
    } else if (object.getClass().isArray()) {
      writeIterable(CollectionUtil.arrayToList(object));
    } else if (object instanceof Iterable) {
      writeIterable((Iterable) object);
    } else if (object instanceof Map) {
      writeMap((Map<?, ?>) object);
    } else if (object instanceof Date) {
      writeDate((Date) object);
    } else {
      writeString(object);
    }
  }
Note: The {@link #writeString} and {@link #hex} methods
are based on code from class {@code StringEscapeUtils} in Commons Lang 2.6.
spock-core/src/main/java/org/spockframework/util/JsonWriter.java