Adds a value to a writer if value is not <code>null</code>.

@param writer
writer to add object to.
@param field
field name to set.
@param value
field value.
@throws JSONException
if io error occurs.
420892
public static void addIfNotNullFull(JSONWriter writer, String field,
			Date value) throws JSONException {
		final SimpleDateFormat format = RedmineDateUtils.FULL_DATE_FORMAT.get();
		JsonOutput.addIfNotNull(writer, field, value, format);
	}
1162724
public void writeValue (String name, Object value) {
		try {
			writer.name(name);
		} catch (IOException ex) {
			throw new JsonException(ex);
		}
		if (value == null)
			writeValue(value, null, null);
		else
			writeValue(value, value.getClass(), null);
	}
536501
@Override
    public void write(final Writer writer) throws ConfigurationException, IOException {
        Preconditions.checkNotNull(writer);

        @SuppressWarnings("unchecked") final
        HashMap<String, Object> settings = (HashMap<String, Object>) fromNode(this.getModel().getInMemoryRepresentation());
        this.mapper.writerWithDefaultPrettyPrinter().writeValue(writer, settings);
    }
192567
public static <T> void registerWriter(Class<?> cls, JsonWriterI<T> writer) {
		defaultWriter.registerWriter(writer, cls);
	}
22814
public static void put(Writer writer, char value) throws IOException {
		writer.write("\"");
		writer.write(sanitize(value));
		writer.write("\"");
	}
1062033
private static void listToWriter(List<?> list, JsonWriter writer) throws IOException {
    writer.beginArray();
    for (Object value : list) {
      writeValue(value, writer);
    }
    writer.endArray();
  }
540236
private void writeJsonKeyValue(String fieldName, String value)
            throws JsonGenerationException, IOException {
        generator.writeStringField(fieldName, value);
    }
466247
public ObjectComposer<PARENT> putObject(String fieldName, Object value)
        throws IOException, JsonProcessingException
    {
        _generator.writeObjectField(fieldName, value);
        return this;
    }
707832
public static void put(Writer writer, Enum<?> value) throws IOException {
		if (value == null) {
			writer.write("null");
		} else {
			writer.write("\"");
			writer.write(sanitize(value.name()));
			writer.write("\"");
		}
	}
1065742
public JsonWriter value(CharSequence value) {
        startValue();

        if (value == null) {
            writer.write(kNull);
        } else {
            writeQuotedAndEscaped(value);
        }
        return this;
    }
322917
public void encodeValue(Writer writer, T obj) throws IOException {
		int count = 0;
		for (String key : map.keySet()) {
			JsonUtil.putKey(writer, key);
			JsonPropertyCoder<T, ?> enc = map.get(key);
			enc.encode(writer, obj);
			count++;
			if (count != map.size()) {
				JsonUtil.addSeparator(writer);
			}
		}
	}
30850
public JsonWriter value(Boolean value) throws IOException {
    if (value == null) {
      return nullValue();
    }
    writeDeferredName();
    beforeValue();
    out.write(value ? "true" : "false");
    return this;
  }
84749
public Writer write(Writer writer) throws JSONException {
        try {
            boolean notFirst = false;
            writer.write('{');
            for(Iterator it = myHashMap.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Entry)it.next();
                if (notFirst) {
                    writer.write(',');
                }
                writeQuoted(writer, entry.getKey());
                writer.write(':');
                writeValue(writer, entry.getValue());
                notFirst = true;
            }
            writer.write('}');
            return writer;
        } catch (IOException e) {
            throw new JSONException(e);
        }
    }
395180
@Override
  public void write(JsonWriterImpl out, char []value)
  {
    out.write(String.valueOf(value, 0, value.length));
  }
161124
public void addWriter(PdfWriter writer) throws DocumentException {
        if (this.writer == null) {
            this.writer = writer;
            annotationsImp = new PdfAnnotationsImp(writer);
            return;
        }
        throw new DocumentException("You can only add a writer to a PdfDocument once.");
    }
3459
private static void addFieldToJsonObject(Method getter, Object o,
                                             String fieldName, JsonObjectBuilder j) {
        try {
            Object fieldValue = getter.invoke(o);

            if (fieldValue == null) {
            } else if (fieldValue instanceof String) {
                j.add(fieldName, (String) fieldValue);
            } else if (fieldValue instanceof Boolean) {
                j.add(fieldName, (Boolean) fieldValue);
            } else if (fieldValue instanceof BigInteger) {
                j.add(fieldName, (BigInteger) fieldValue);
            } else if (fieldValue instanceof java.math.BigDecimal) {
                j.add(fieldName, (BigDecimal) fieldValue);
            } else if (fieldValue instanceof Double) {
                j.add(fieldName, (Double) fieldValue);
            } else if (fieldValue instanceof Integer) {
                j.add(fieldName, (Integer) fieldValue);
            } else if (fieldValue instanceof Long) {
                j.add(fieldName, (Long) fieldValue);
            } else if (fieldValue instanceof Short) {
                j.add(fieldName, (Short) fieldValue);
            } else if (fieldValue instanceof Byte) {
                j.add(fieldName, (Byte) fieldValue);

            } else if (fieldValue instanceof Enum) {
                try {
                    // enums need careful handling.. look for get/set Value to use.
                    Method getValueForEnumMethod = fieldValue.getClass().getMethod("getValue");
                    Object valueFromGetValueMethod = getValueForEnumMethod.invoke(fieldValue);
                    j.add(fieldName, valueFromGetValueMethod.toString());
                } catch (NoSuchMethodException e) {
                    // else fallback to toString
                    j.add(fieldName, fieldValue.toString());
                }
            } else if (fieldValue instanceof Collection
                       || fieldValue.getClass().getName().startsWith(DATA_MODEL_PACKAGE)) {
                JSONArtrifactPair fieldObjects = findFieldsToSerialize(fieldValue);
                j.add(fieldName, fieldObjects.mainObject);
                if (fieldObjects.incompatibleFieldsObject != null && !fieldObjects.incompatibleFieldsObject.isEmpty()) {
                    // As per the contract on the HasBreakingChanges interface store incompatible fields in a second object
                    j.add(fieldName + "2", fieldObjects.incompatibleFieldsObject);
                }
            } else if (fieldValue instanceof Calendar) {
                Date date = ((Calendar) fieldValue).getTime();
                j.add(fieldName, getDateFormat().format(date));
            } else if (fieldValue instanceof Date) {
                j.add(fieldName, getDateFormat().format((Date) fieldValue));
            } else if (fieldValue instanceof Locale) {
                //note that Locale toString is a bit fiddly to round trip, but it's the best we have for now.
                String localeString = ((Locale) fieldValue).toString();
                j.add(fieldName, localeString);
            } else {
                throw new IllegalStateException("Data Model Error: Unknown data model entity "
                                                + getter.getName() + " of type " + fieldValue.getClass().getName() + " on "
                                                + o.getClass().getName());
            }

        } catch (IllegalAccessException e) {
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        } catch (IllegalArgumentException e) {
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        } catch (InvocationTargetException e) {
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        } catch (JsonException e) {
            // Shouldn't happen unless field name is null or the value cannot be converted
            throw new IllegalStateException("Data Model Error: unable to invoke getter "
                                            + getter.getName() + " on "
                                            + o.getClass().getName(), e);
        }
    }
883439
public final void writeNumberField(String fieldName, int value)
        throws IOException, JsonGenerationException
    {
        writeFieldName(fieldName);
        writeNumber(value);
    }