Encode properties to database representation.

NULL values are preserved.

You should not need to call this, it is called automaticaly at the right time.
345506
public function encodeProperties($properties)
	{
		// Replace empty values with null, if value is not required
		foreach ($properties as $k => & $v) {
			if (isset($this->properties[$k])) {
				$prop = $this->properties[$k];
				if (empty($prop['required']) && ($v === array() || (is_string($v) && ctype_space($v)))) {
					$v = null;
				}
			} else {
				// Value is not valid property, throw it away
				unset($properties[$k]);
			}
		}

		// Split composed properties to individual columns
		foreach ($this->composed_properties as $property => $components) {
			foreach ($components as $component => $column) {
				if (isset($properties[$property][$component])) {
					$properties[$column] = $properties[$property][$component];
				} else {
					$properties[$column] = null;
				}
			}
			unset($properties[$property]);
		}

		// Encode JSON columns
		foreach ($this->json_columns as $column_name) {
			if (isset($properties[$column_name])) {
				$json_data = json_encode($properties[$column_name], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_NUMERIC_CHECK);
				if ($json_data === FALSE) {
					switch (json_last_error()) {
						case JSON_ERROR_NONE: $json_error = 'No error has occurred'; break;
						case JSON_ERROR_DEPTH: $json_error = 'The maximum stack depth has been exceeded'; break;
						case JSON_ERROR_STATE_MISMATCH: $json_error = 'Invalid or malformed JSON'; break;
						case JSON_ERROR_CTRL_CHAR: $json_error = 'Control character error, possibly incorrectly encoded'; break;
						case JSON_ERROR_SYNTAX: $json_error = 'Syntax error'; break;
						case JSON_ERROR_UTF8: $json_error = 'Malformed UTF-8 characters, possibly incorrectly encoded'; break;
						case JSON_ERROR_RECURSION: $json_error = 'One or more recursive references in the value to be encoded'; break;
						case JSON_ERROR_INF_OR_NAN: $json_error = 'One or more NAN or INF values in the value to be encoded'; break;
						case JSON_ERROR_UNSUPPORTED_TYPE: $json_error = 'A value of a type that cannot be encoded was given'; break;
						default: $json_error = 'Error '.json_last_error(); break;
					}
					throw new \InvalidArgumentException('Failed to serialize invoice data to JSON: '.$json_error);
				}
				$properties[$column_name] = $json_data;
			}
		}

		return $properties;
	}
45560
function encode(data) {
  var encodedData = null;
  try {
    encodedData = JSON.stringify(data);
  } catch (err) {
    logger.warn('failed encoding data', data);
  }
  return encodedData;
}
68108
private void encodeEnum(GeneratorAdapter mg, TypeToken<?> outputType,
                          int value, int encoder, int schemaLocal) {

    // encoder.writeInt(this.schema.getEnumIndex(value.name()));
    mg.loadArg(encoder);
    mg.loadArg(schemaLocal);
    mg.loadArg(value);
    mg.invokeVirtual(Type.getType(outputType.getRawType()), getMethod(String.class, "name"));
    mg.invokeVirtual(Type.getType(Schema.class), getMethod(int.class, "getEnumIndex", String.class));
    mg.invokeInterface(Type.getType(Encoder.class), getMethod(Encoder.class, "writeInt", int.class));
    mg.pop();
  }
1271870
public function encode()
    {
        if (!empty($this->attributes)) {
            foreach ($this->attributes as $name => $params) {
                if (is_numeric($name)) {
                    $name = $params;
                }
                /** @var ActiveRecord $owner */
                $owner = $this->owner;
                if ($owner->hasAttribute($name)) {
                    $owner->setAttribute($name, Json::encode($owner->getAttribute($name)));
                }
            }
        }
    }
1085169
private void encodeUnion(GeneratorAdapter mg, TypeToken<?> outputType, Schema schema,
                           int value, int encoder, int schemaLocal, int seenRefs) {
    Label nullLabel = mg.newLabel();
    Label endLabel = mg.newLabel();
    mg.loadArg(value);

    mg.ifNull(nullLabel);
    // Not null, write out 0 and then encode the value
    encodeInt(mg, 0, encoder);

    mg.loadThis();
    mg.loadArg(value);
    doCast(mg, outputType, schema.getUnionSchema(0));
    mg.loadArg(encoder);
    mg.loadArg(schemaLocal);
    mg.push(0);
    mg.invokeVirtual(Type.getType(Schema.class), getMethod(Schema.class, "getUnionSchema", int.class));
    mg.loadArg(seenRefs);
    mg.invokeVirtual(classType, getEncodeMethod(outputType, schema.getUnionSchema(0)));

    mg.goTo(endLabel);

    mg.mark(nullLabel);
    // Null, write out 1
    encodeInt(mg, 1, encoder);
    mg.mark(endLabel);
  }
97807
private int encodeProperty(CodeAssembler a, TypeDesc type, Mode mode, boolean descending) {
        TypeDesc[] params = new TypeDesc[] {
            type, TypeDesc.forClass(byte[].class), TypeDesc.INT
        };

        if (type.isPrimitive()) {
            if (mode == Mode.KEY && descending) {
                a.invokeStatic(KeyEncoder.class.getName(), "encodeDesc", null, params);
            } else {
                a.invokeStatic(DataEncoder.class.getName(), "encode", null, params);
            }

            switch (type.getTypeCode()) {
            case TypeDesc.BYTE_CODE:
            case TypeDesc.BOOLEAN_CODE:
                return 1;
            case TypeDesc.SHORT_CODE:
            case TypeDesc.CHAR_CODE:
                return 2;
            default:
            case TypeDesc.INT_CODE:
            case TypeDesc.FLOAT_CODE:
                return 4;
            case TypeDesc.LONG_CODE:
            case TypeDesc.DOUBLE_CODE:
                return 8;
            }
        } else if (type.toPrimitiveType() != null) {
            // Type is a primitive wrapper.

            int adjust;
            TypeDesc retType;

            switch (type.toPrimitiveType().getTypeCode()) {
            case TypeDesc.BOOLEAN_CODE:
                adjust = 1;
                retType = null;
                break;
            case TypeDesc.FLOAT_CODE:
                adjust = 4;
                retType = null;
                break;
            case TypeDesc.DOUBLE_CODE:
                adjust = 8;
                retType = null;
                break;
            default:
                adjust = 0;
                retType = TypeDesc.INT;
            }

            if (mode == Mode.KEY && descending) {
                a.invokeStatic(KeyEncoder.class.getName(), "encodeDesc", retType, params);
            } else {
                a.invokeStatic(DataEncoder.class.getName(), "encode", retType, params);
            }

            return adjust;
        } else {
            // Type is a String, byte array, BigInteger or BigDecimal.
            if (mode == Mode.KEY) {
                if (descending) {
                    a.invokeStatic
                        (KeyEncoder.class.getName(), "encodeDesc", TypeDesc.INT, params);
                } else {
                    a.invokeStatic(KeyEncoder.class.getName(), "encode", TypeDesc.INT, params);
                }
            } else {
                a.invokeStatic(DataEncoder.class.getName(), "encode", TypeDesc.INT, params);
            }
            return 0;
        }
    }
562370
private String encode(Object value) {
    return BaseEncoding.base16().encode(valueSerializer.encode(value));
  }
955232
function encodeQueryAsString(query = {}) {
  const params = Object.keys(query).map((name) =>
    [encodeURIComponent(name), encodeURIComponent(query[name])].join('=')
  );
  return params.length ? `?${params.join('&')}` : '';
}
257460
public function charsetEncodeDbToOutput()
    {
        if ($this->db_charset && $this->output_charset) {
            if ($this->db_charset != $this->output_charset) {
                foreach ($this->columns as $col) {
                    $col->column_value = iconv($this->db_charset, $this->output_charset, $col->column_value);
                }
            }
        }

    }
338895
@Override
    public void setNull(int parameterIndex, int sqlType) throws SQLException
    {
        checkParameterBounds(parameterIndex);
        switch(sqlType)
        {
            case Types.TINYINT:
                this.parameters[parameterIndex-1] = VoltType.NULL_TINYINT;
                break;
            case Types.SMALLINT:
                this.parameters[parameterIndex-1] = VoltType.NULL_SMALLINT;
                break;
            case Types.INTEGER:
                this.parameters[parameterIndex-1] = VoltType.NULL_INTEGER;
                break;
            case Types.BIGINT:
                this.parameters[parameterIndex-1] = VoltType.NULL_BIGINT;
                break;
            case Types.DOUBLE:
                this.parameters[parameterIndex-1] = VoltType.NULL_FLOAT;
                break;
            case Types.DECIMAL:
                this.parameters[parameterIndex-1] = VoltType.NULL_DECIMAL;
                break;
            case Types.TIMESTAMP:
                this.parameters[parameterIndex-1] = VoltType.NULL_TIMESTAMP;
                break;
            case Types.VARBINARY:
            case Types.VARCHAR:
            case Types.NVARCHAR:
            case Types.OTHER:
            case Types.NULL:
                this.parameters[parameterIndex-1] = VoltType.NULL_STRING_OR_VARBINARY;
                break;
            default:
                throw SQLError.get(SQLError.ILLEGAL_ARGUMENT);
        }
    }
590236
@Override
	@Nullable
	public String getEncoding() {
		return (this.dataSource instanceof EncodingAware) ? ((EncodingAware) this.dataSource).getEncoding() : null;
	}
1274267
private String encode(String message) {
        return message == null ? null : message.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
    }
69798
function encodeQueryData(obj, prefix) {
          var str = [];
          for (var p in obj) {
            if (obj.hasOwnProperty(p)) {
              var k = prefix ? prefix + '[' + p + ']' : p, v = obj[p];
              str.push(typeof v === 'object' ? encodeQueryData(v, k) : encodeURIComponent(k) + '=' + encodeURIComponent(v));
            }
          }
          return str.join('&');
        }
754469
private void _serialize(Object object, StringBuilder sb, Set<Object> done) throws ConverterException {
	// try {
	deep++;
	// NULL
	if (object == null) {
	    sb.append(goIn());
	    sb.append("nullValue()");
	    deep--;
	    return;
	}
	// String
	if (object instanceof String) {
	    sb.append(goIn());
	    sb.append(QUOTE_CHR);
	    sb.append(escape(object.toString()));
	    sb.append(QUOTE_CHR);
	    deep--;
	    return;
	}
	if (object instanceof TimeZone) {
	    sb.append(goIn());
	    sb.append(QUOTE_CHR);
	    sb.append(escape(((TimeZone) object).getID()));
	    sb.append(QUOTE_CHR);
	    deep--;
	    return;
	}
	if (object instanceof Locale) {
	    sb.append(goIn());
	    sb.append(QUOTE_CHR);
	    sb.append(LocaleFactory.toString((Locale) object));
	    sb.append(QUOTE_CHR);
	    deep--;
	    return;
	}
	// Number
	if (object instanceof Number) {
	    sb.append(goIn());
	    sb.append(Caster.toString(((Number) object)));
	    deep--;
	    return;
	}
	// Boolean
	if (object instanceof Boolean) {
	    sb.append(goIn());
	    sb.append(Caster.toString(((Boolean) object).booleanValue()));
	    deep--;
	    return;
	}
	// DateTime
	if (object instanceof DateTime) {
	    _serializeDateTime((DateTime) object, sb);
	    deep--;
	    return;
	}
	// Date
	if (object instanceof Date) {
	    _serializeDate((Date) object, sb);
	    deep--;
	    return;
	}
	// XML
	if (object instanceof Node) {
	    _serializeXML((Node) object, sb);
	    deep--;
	    return;
	}
	if (object instanceof ObjectWrap) {
	    try {
		_serialize(((ObjectWrap) object).getEmbededObject(), sb, done);
	    }
	    catch (PageException e) {
		throw toConverterException(e);
	    }
	    deep--;
	    return;
	}
	// Timespan
	if (object instanceof TimeSpan) {
	    _serializeTimeSpan((TimeSpan) object, sb);
	    deep--;
	    return;
	}
	Object raw = LazyConverter.toRaw(object);
	if (done.contains(raw)) {
	    sb.append(goIn());
	    sb.append("nullValue()");
	    deep--;
	    return;
	}

	done.add(raw);
	try {
	    // Component
	    if (object instanceof Component) {
		_serializeComponent((Component) object, sb, done);
		deep--;
		return;
	    }

	    // Struct
	    if (object instanceof Struct) {
		_serializeStruct((Struct) object, sb, done);
		deep--;
		return;
	    }
	    // Map
	    if (object instanceof Map) {
		_serializeMap((Map) object, sb, done);
		deep--;
		return;
	    }
	    // Array
	    if (object instanceof Array) {
		_serializeArray((Array) object, sb, done);
		deep--;
		return;
	    }
	    // List
	    if (object instanceof List) {
		_serializeList((List) object, sb, done);
		deep--;
		return;
	    }
	    // Query
	    if (object instanceof Query) {
		_serializeQuery((Query) object, sb, done);
		deep--;
		return;
	    }
	    // String Converter
	    if (object instanceof ScriptConvertable) {
		sb.append(((ScriptConvertable) object).serialize());
		deep--;
		return;
	    }
	    if (object instanceof Serializable) {
		_serializeSerializable((Serializable) object, sb);
		deep--;
		return;
	    }
	}
	finally {
	    done.remove(raw);
	}
	throw new ConverterException("can't serialize Object of type [ " + Caster.toClassName(object) + " ]");
	// deep--;
	/*
	 * } catch(StackOverflowError soe){ throw soe; }
	 */
    }
79056
public void encodeNullToNull(Writer writer, T obj) throws IOException {
		if (obj == null) {
			writer.write("null");
			return;
		}

		JsonUtil.startHash(writer);

		encodeValue(writer, obj);

		JsonUtil.endHash(writer);

		writer.flush();
	}
507716
private String addAndEncodeValue(String originalValue, String newValue,
      boolean encode) {
    return addAndEncode(originalValue, null, newValue, encode);
  }
63429
public void setValue(Properties properties)  {
        if (properties == null) {
            throw new IllegalArgumentException("properties must not be null");
        }
        if (type == null) {
            type = ItemType.PROPERTIES;
        }
        if (!isMappableType()) {
            throw new IllegalArgumentException("The type of this item must be 'properties' or 'map'");
        }
        tokensMap = new LinkedHashMap<>();
        for (String key : properties.stringPropertyNames()) {
            Object o = properties.get(key);
            if (o instanceof Token[]) {
                tokensMap.put(key, (Token[])o);
            } else if (o instanceof Token) {
                Token[] tokens = new Token[] { (Token)o };
                tokensMap.put(key, tokens);
            } else {
                Token[] tokens = TokenParser.makeTokens(o.toString(), isTokenize());
                putValue(name, tokens);
            }
        }
    }