Class XContentHelper
- java.lang.Object
-
- org.elasticsearch.common.xcontent.XContentHelper
-
public class XContentHelper extends Object
-
-
Constructor Summary
Constructors Constructor Description XContentHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static StringconvertToJson(BytesReference bytes, boolean reformatJson)Deprecated.static StringconvertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint)Deprecated.static StringconvertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint, XContentType xContentType)static StringconvertToJson(BytesReference bytes, boolean reformatJson, XContentType xContentType)static Tuple<XContentType,Map<String,Object>>convertToMap(BytesReference bytes, boolean ordered)Deprecated.this method relies on auto-detection of content type.static Tuple<XContentType,Map<String,Object>>convertToMap(BytesReference bytes, boolean ordered, XContentType xContentType)Converts the given bytes into a map that is optionally ordered.static Map<String,Object>convertToMap(XContent xContent, InputStream input, boolean ordered)static Map<String,Object>convertToMap(XContent xContent, String string, boolean ordered)static XContentParsercreateParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler, BytesReference bytes)Deprecated.usecreateParser(NamedXContentRegistry, DeprecationHandler, BytesReference, XContentType)to avoid content type auto-detectionstatic XContentParsercreateParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler, BytesReference bytes, XContentType xContentType)Creates a parser for the bytes using the supplied content-typestatic voidmergeDefaults(Map<String,Object> content, Map<String,Object> defaults)Merges the defaults provided as the second parameter into the content of the first.static BytesReferencetoXContent(ToXContent toXContent, XContentType xContentType, boolean humanReadable)Returns the bytes that represent the XContent output of the providedToXContentobject, using the providedXContentType.static BytesReferencetoXContent(ToXContent toXContent, XContentType xContentType, ToXContent.Params params, boolean humanReadable)Returns the bytes that represent the XContent output of the providedToXContentobject, using the providedXContentType.static booleanupdate(Map<String,Object> source, Map<String,Object> changes, boolean checkUpdatesAreUnequal)Updates the provided changes into the source.static voidwriteRawField(String field, BytesReference source, XContentBuilder builder, ToXContent.Params params)Deprecated.usewriteRawField(String, BytesReference, XContentType, XContentBuilder, Params)to avoid content type auto-detectionstatic voidwriteRawField(String field, BytesReference source, XContentType xContentType, XContentBuilder builder, ToXContent.Params params)Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing usingXContentBuilder.rawField(String, InputStream, XContentType).static XContentTypexContentType(BytesReference bytes)Deprecated.the content type should not be guessed except for few cases where we effectively don't know the content type.
-
-
-
Method Detail
-
createParser
@Deprecated public static XContentParser createParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler, BytesReference bytes) throws IOException
Deprecated.usecreateParser(NamedXContentRegistry, DeprecationHandler, BytesReference, XContentType)to avoid content type auto-detectionCreates a parser based on the bytes provided- Throws:
IOException
-
createParser
public static XContentParser createParser(NamedXContentRegistry xContentRegistry, DeprecationHandler deprecationHandler, BytesReference bytes, XContentType xContentType) throws IOException
Creates a parser for the bytes using the supplied content-type- Throws:
IOException
-
convertToMap
@Deprecated public static Tuple<XContentType,Map<String,Object>> convertToMap(BytesReference bytes, boolean ordered) throws ElasticsearchParseException
Deprecated.this method relies on auto-detection of content type. UseconvertToMap(BytesReference, boolean, XContentType)instead with the properXContentTypeConverts the given bytes into a map that is optionally ordered.- Throws:
ElasticsearchParseException
-
convertToMap
public static Tuple<XContentType,Map<String,Object>> convertToMap(BytesReference bytes, boolean ordered, XContentType xContentType) throws ElasticsearchParseException
Converts the given bytes into a map that is optionally ordered. The providedXContentTypemust be non-null.- Throws:
ElasticsearchParseException
-
convertToMap
public static Map<String,Object> convertToMap(XContent xContent, String string, boolean ordered) throws ElasticsearchParseException
Convert a string in someXContentformat to aMap. Throws anElasticsearchParseExceptionif there is any error.- Throws:
ElasticsearchParseException
-
convertToMap
public static Map<String,Object> convertToMap(XContent xContent, InputStream input, boolean ordered) throws ElasticsearchParseException
Convert a string in someXContentformat to aMap. Throws anElasticsearchParseExceptionif there is any error. Note that unlikeconvertToMap(BytesReference, boolean), this doesn't automatically uncompress the input.- Throws:
ElasticsearchParseException
-
convertToJson
@Deprecated public static String convertToJson(BytesReference bytes, boolean reformatJson) throws IOException
Deprecated.- Throws:
IOException
-
convertToJson
@Deprecated public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint) throws IOException
Deprecated.- Throws:
IOException
-
convertToJson
public static String convertToJson(BytesReference bytes, boolean reformatJson, XContentType xContentType) throws IOException
- Throws:
IOException
-
convertToJson
public static String convertToJson(BytesReference bytes, boolean reformatJson, boolean prettyPrint, XContentType xContentType) throws IOException
- Throws:
IOException
-
update
public static boolean update(Map<String,Object> source, Map<String,Object> changes, boolean checkUpdatesAreUnequal)
Updates the provided changes into the source. If the key exists in the changes, it overrides the one in source unless both are Maps, in which case it recursively updated it.- Parameters:
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.- Returns:
- true if the source map was modified
-
mergeDefaults
public static void mergeDefaults(Map<String,Object> content, Map<String,Object> defaults)
Merges the defaults provided as the second parameter into the content of the first. Only does recursive merge for inner maps.
-
writeRawField
@Deprecated public static void writeRawField(String field, BytesReference source, XContentBuilder builder, ToXContent.Params params) throws IOException
Deprecated.usewriteRawField(String, BytesReference, XContentType, XContentBuilder, Params)to avoid content type auto-detectionWrites a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing usingXContentBuilder.rawField(String, InputStream).- Throws:
IOException
-
writeRawField
public static void writeRawField(String field, BytesReference source, XContentType xContentType, XContentBuilder builder, ToXContent.Params params) throws IOException
Writes a "raw" (bytes) field, handling cases where the bytes are compressed, and tries to optimize writing usingXContentBuilder.rawField(String, InputStream, XContentType).- Throws:
IOException
-
toXContent
public static BytesReference toXContent(ToXContent toXContent, XContentType xContentType, boolean humanReadable) throws IOException
Returns the bytes that represent the XContent output of the providedToXContentobject, using the providedXContentType. Wraps the output into a new anonymous object according to the value returned by theToXContent.isFragment()method returns.- Throws:
IOException
-
toXContent
public static BytesReference toXContent(ToXContent toXContent, XContentType xContentType, ToXContent.Params params, boolean humanReadable) throws IOException
Returns the bytes that represent the XContent output of the providedToXContentobject, using the providedXContentType. Wraps the output into a new anonymous object according to the value returned by theToXContent.isFragment()method returns.- Throws:
IOException
-
xContentType
@Deprecated public static XContentType xContentType(BytesReference bytes)
Deprecated.the content type should not be guessed except for few cases where we effectively don't know the content type. The REST layer should move to reading the Content-Type header instead. There are other places where auto-detection may be needed. This method is deprecated to prevent usages of it from spreading further without specific reasons.Guesses the content type based on the provided bytes.
-
-