public class XContentHelper
extends java.lang.Object
Constructor and Description |
---|
XContentHelper() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
convertToJson(BytesReference bytes,
boolean reformatJson) |
static java.lang.String |
convertToJson(BytesReference bytes,
boolean reformatJson,
boolean prettyPrint) |
static Tuple<XContentType,java.util.Map<java.lang.String,java.lang.Object>> |
convertToMap(BytesReference bytes,
boolean ordered) |
static java.util.Map<java.lang.String,java.lang.Object> |
convertToMap(XContent xContent,
java.io.InputStream input,
boolean ordered)
Convert a string in some
XContent format to a Map . |
static java.util.Map<java.lang.String,java.lang.Object> |
convertToMap(XContent xContent,
java.lang.String string,
boolean ordered)
Convert a string in some
XContent format to a Map . |
static void |
copyCurrentEvent(XContentGenerator generator,
XContentParser parser) |
static void |
copyCurrentStructure(XContentGenerator destination,
XContentParser parser)
Low level implementation detail of
XContentGenerator.copyCurrentStructure(XContentParser) . |
static XContentParser |
createParser(NamedXContentRegistry xContentRegistry,
BytesReference bytes) |
static void |
mergeDefaults(java.util.Map<java.lang.String,java.lang.Object> content,
java.util.Map<java.lang.String,java.lang.Object> defaults)
Merges the defaults provided as the second parameter into the content of the first.
|
static java.lang.String |
toString(ToXContent toXContent)
Writes serialized toXContent to pretty-printed JSON string.
|
static java.lang.String |
toString(ToXContent toXContent,
ToXContent.Params params)
Writes serialized toXContent to pretty-printed JSON string.
|
static BytesReference |
toXContent(ToXContent toXContent,
XContentType xContentType,
boolean wrapInObject)
Returns the bytes that represent the XContent output of the provided
ToXContent object, using the provided
XContentType . |
static boolean |
update(java.util.Map<java.lang.String,java.lang.Object> source,
java.util.Map<java.lang.String,java.lang.Object> changes,
boolean checkUpdatesAreUnequal)
Updates the provided changes into the source.
|
static void |
writeRawField(java.lang.String field,
BytesReference source,
XContentBuilder builder,
ToXContent.Params params)
Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing using
XContentBuilder.rawField(String, org.elasticsearch.common.bytes.BytesReference) . |
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, BytesReference bytes) throws java.io.IOException
java.io.IOException
public static Tuple<XContentType,java.util.Map<java.lang.String,java.lang.Object>> convertToMap(BytesReference bytes, boolean ordered) throws ElasticsearchParseException
ElasticsearchParseException
public static java.util.Map<java.lang.String,java.lang.Object> convertToMap(XContent xContent, java.lang.String string, boolean ordered) throws ElasticsearchParseException
XContent
format to a Map
. Throws an ElasticsearchParseException
if there is any
error.ElasticsearchParseException
public static java.util.Map<java.lang.String,java.lang.Object> convertToMap(XContent xContent, java.io.InputStream input, boolean ordered) throws ElasticsearchParseException
XContent
format to a Map
. Throws an ElasticsearchParseException
if there is any
error. Note that unlike convertToMap(BytesReference, boolean)
, this doesn't automatically uncompress the input.ElasticsearchParseException
public static java.lang.String convertToJson(BytesReference bytes, boolean reformatJson) throws java.io.IOException
java.io.IOException
public static java.lang.String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint) throws java.io.IOException
java.io.IOException
public static java.lang.String toString(ToXContent toXContent)
toXContent
- object to be pretty printedpublic static java.lang.String toString(ToXContent toXContent, ToXContent.Params params)
toXContent
- object to be pretty printedparams
- serialization parameterspublic static boolean update(java.util.Map<java.lang.String,java.lang.Object> source, java.util.Map<java.lang.String,java.lang.Object> changes, boolean checkUpdatesAreUnequal)
source
- the original map to be updatedchanges
- the changes to update into updatedcheckUpdatesAreUnequal
- should this method check if updates to the same key (that are not both maps) are
unequal? This is just a .equals check on the objects, but that can take some time on long strings.public static void mergeDefaults(java.util.Map<java.lang.String,java.lang.Object> content, java.util.Map<java.lang.String,java.lang.Object> defaults)
public static void copyCurrentStructure(XContentGenerator destination, XContentParser parser) throws java.io.IOException
XContentGenerator.copyCurrentStructure(XContentParser)
.java.io.IOException
public static void copyCurrentEvent(XContentGenerator generator, XContentParser parser) throws java.io.IOException
java.io.IOException
public static void writeRawField(java.lang.String field, BytesReference source, XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
XContentBuilder.rawField(String, org.elasticsearch.common.bytes.BytesReference)
.java.io.IOException
public static BytesReference toXContent(ToXContent toXContent, XContentType xContentType, boolean wrapInObject) throws java.io.IOException
ToXContent
object, using the provided
XContentType
. Wraps the output into a new anonymous object depending on the value of the wrapInObject argument.java.io.IOException