Serializes an object and appends it to the stream.

@param value - an object to serialize
@return the JSONBuilder itself
545559
public JSONBuilder serialize(Object value) {
        if (value == null) {
            _sb.append("null");
        } else {
            Class<?> t = value.getClass();
            if (t.isArray()) {
                _sb.append('[');
                boolean hasElements = false;
                for (int i = 0, ii = Array.getLength(value); i < ii; ++i) {
                    serialize(Array.get(value, i));
                    _sb.append(',');
                    hasElements = true;
                }
                if (hasElements) {
                    _sb.setCharAt(_sb.length()-1, ']');
                } else {
                    _sb.append(']');
                }
            } else if (Iterable.class.isAssignableFrom(t)) {
                _sb.append('[');
                boolean hasElements = false;
                for (Object object: (Iterable<?>)value) {
                    serialize(object);
                    _sb.append(',');
                    hasElements = true;
                }
                if (hasElements) {
                    _sb.setCharAt(_sb.length()-1, ']');
                } else {
                    _sb.append(']');
                }
            } else if (Number.class.isAssignableFrom(t) || Boolean.class.isAssignableFrom(t)) {
                _sb.append(value.toString());
            } else if (String.class == t) {
                quote((String)value);
            } else {
                quote(value.toString());
            }
        }
        return this;
    }
821816
private static JsonStructure toJson( VarValueDef value)
    {
    JsonObjectBuilder builder = Json.createObjectBuilder();

    if( value.getType().equals( FAILURE))
      {
      builder.add( FAILURE_KEY, true);
      }
    else if( value.getType().equals( ONCE))
      {
      builder.add( ONCE_KEY, true);
      }

    addAnnotations( builder, value);

    ConditionJson.toJson( value).ifPresent( json -> builder.add( WHEN_KEY, json));
      
    addProperties( builder, value);

    return builder.build();
    }
1293262
private Class<?> serializerToClass(String value) {
    try {
      return Thread.currentThread().getContextClassLoader().loadClass(value);
    } catch (ClassNotFoundException e) {
      throw new ConfigurationException("unknown serializable type: " + value);
    }
  }
731720
public Serializer writeArray(JSONArray value) throws IOException {
        if (null == value) return writeNull();

        // write header
        writeRawString("[");
        indentPush();

        for (Iterator iter=value.iterator(); iter.hasNext(); )
        {
            Object element = iter.next();
            if (!JSONObject.isValidObject(element)) throw new IOException("attempting to serialize array with an invalid element: '" + value + "'");

            newLine();
            indent();
            write(element);

            if (iter.hasNext()) writeRawString(",");
        }

        // write trailer
        indentPop();
        newLine();
        indent();
        writeRawString("]");

        return this;
    }
433029
private JsonObject createMessage(Object value) {
    // Tag the message with a monotonically increasing ID. The ID
    // will be used by the other side of the connection to guarantee
    // ordering.
    JsonObject message = serializer.serialize(value);
    long id = currentMessage++;
    message.putNumber("id", id);
    messages.put(id, message);
    return message;
  }
785289
public JsonWriter value(Binary value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write('\"');
            writer.write(value.toBase64());
            writer.write('\"');
        }
        return this;
    }
1140824
public JsonArray add(JsonValue value) {
    if (value == null) {
      throw new NullPointerException("value is null");
    }
    values.add(value);
    return this;
  }
184238
public static Instant parseJsonDate(String value) {
        if (value == null) {
            return null;
        }
        return LocalDateTime.parse(value, JSON_DATETIME_FORMAT).atOffset(ZoneOffset.UTC).toInstant();
    }
808012
@Override
	public Long serialize(Date value) {
		if (value != null) {
			return value.getTime();
		}
		return null;
	}
1317325
public JsonWriter value(double value) {
        startValue();

        final long i = (long) value;
        if (value == (double) i) {
            writer.print(i);
        } else {
            writer.print(value);
        }
        return this;
    }
542388
private static List<JsonObject> getJsonValueAsList(JsonValue value) {
        if (value != null) {
            if (value.getValueType() == ValueType.ARRAY) {
                return value.asJsonArray().getValuesAs(JsonObject.class);

            } else if (value.getValueType() == ValueType.OBJECT) {
                List<JsonObject> ret = new ArrayList<>();
                ret.add(value.asJsonObject());

                return ret;
            }
        }
        return null;
    }
1369416
public PropertiesWriter append( final String key, final String value )
    {
        NullArgumentException.validateNotEmpty( key, "Key" );
        String valueToAdd = value;
        if( value == null )
        {
            valueToAdd = "";
        }
        Integer position = m_positions.get( key );
        List<String> values = m_values.get( key );
        if( values == null )
        {
            values = new ArrayList<String>();
            m_values.put( key, values );
        }
        values.add( valueToAdd );
        StringBuilder builder = new StringBuilder().append( key ).append( "=" );
        if( values.size() == 1 )
        {
            builder.append( valueToAdd );
        }
        else
        {
            builder.append( "\\\n" );
            String trail = null;
            for( String storedValue : values )
            {
                if( trail != null )
                {
                    builder.append( trail );
                }
                builder.append( storedValue );
                trail = m_separator + "\\\n";
            }
        }
        if( position == null )
        {
            m_content.add( builder.toString() );
            m_positions.put( key, m_content.size() - 1 );
        }
        else
        {
            m_content.set( position, builder.toString() );
        }
        return this;
    }
1143661
public JsonWriter valueLiteral(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writer.write(value.toString());
        }
        return this;
    }
418909
public static byte[] asBytesUnchecked(final Object value) {
    try {
      return OBJECT_MAPPER.writeValueAsBytes(value);
    } catch (JsonProcessingException e) {
      throw new RuntimeException(e);
    }
  }
1089457
public static String toJsonString(Object value) {
        if (value == null) {
            return "null";
        }
        else if (value.getClass().equals(String.class)) {
            return "\"" + StringUtils.jsonEncoding(value.toString()) + "\"";
        }
        // else it's a RawJson, Boolean or Number so no escaping or quotes
        else {
            return value.toString();
        }
    }
308201
public static String toJson(Object value) {
        if (value instanceof String) {
            return '"' + (String) value + '"';
        } else if (value instanceof Collection) {
            return "[" + toJsonCollection((Collection) value) + "]";
        } else {
            throw new IllegalArgumentException("Unable to convert " + value + " to JSON");
        }
    }
755358
public static byte[] serialize(Object value) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    serialize(value, out);
    return out.toByteArray();
  }