public final class ComplexKey
extends java.lang.Object
If you use the ComplexKex class, the stored objects ultimately get converted into a JSON string. As a result, make sure your custom objects implement the "toString" method accordingly (unless you work with trivial types like Strings or numbers).
Instead of using a constructor, use the static "of" method to generate your objects. You can also use a special empty object or array.
Here are some simple examples:
// generated JSON: [2012,9,7]
ComplexKey.of(2012, 9, 7);
// generated JSON: ["Hello","World",5.12]
ComplexKey.of("Hello", "World", 5.12);
// generated JSON: {}
ComplexKey.of(ComplexKey.emptyObject());
// generated JSON: []
ComplexKey.of(ComplexKey.emptyArray());
This was inspired by the Ektorp project, which queries Apache CouchDB.Modifier and Type | Method and Description |
---|---|
static java.lang.Object[] |
emptyArray()
Returns an empty array of objects.
|
static java.lang.Object |
emptyObject()
Returns a single empty object.
|
ComplexKey |
forceArray(boolean force)
Force the cast to a JSON array even when there is only one element.
|
static ComplexKey |
of(java.lang.Object... components)
Generate a ComplexKey based on the input Object arguments (varargs).
|
java.lang.String |
toJson()
Generate a JSON string of the ComplexKey.
|
public static ComplexKey of(java.lang.Object... components)
components
- List of objects that should be convertedpublic static java.lang.Object emptyObject()
public static java.lang.Object[] emptyArray()
public ComplexKey forceArray(boolean force)
force
- whether the ComplexKey should be forced to be an array or not.public java.lang.String toJson()
Copyright © 2006-2009 Dustin Sallings, 2009-2012 Couchbase, Inc.