add the ability to control the content type the map will serialize under
This commit is contained in:
parent
7a01b19b8d
commit
5603c4d09c
|
@ -214,13 +214,22 @@ public class IndexRequest extends ShardReplicationOperationRequest {
|
|||
}
|
||||
|
||||
/**
|
||||
* Writes the JSON as a {@link Map}.
|
||||
* Writes the Map as a JSON.
|
||||
*
|
||||
* @param source The map to index
|
||||
*/
|
||||
@Required public IndexRequest source(Map source) throws ElasticSearchGenerationException {
|
||||
return source(source, XContentType.JSON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the JSON as the provided content type.
|
||||
*
|
||||
* @param source The map to index
|
||||
*/
|
||||
@Required public IndexRequest source(Map source, XContentType contentType) throws ElasticSearchGenerationException {
|
||||
try {
|
||||
BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(XContentType.JSON);
|
||||
BinaryXContentBuilder builder = XContentFactory.contentBinaryBuilder(contentType);
|
||||
builder.map(source);
|
||||
this.source = builder.copiedBytes();
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -20,11 +20,19 @@
|
|||
package org.elasticsearch.util.xcontent;
|
||||
|
||||
/**
|
||||
* The content type of {@link org.elasticsearch.util.xcontent.XContent}.
|
||||
*
|
||||
* @author kimchy (shay.banon)
|
||||
*/
|
||||
public enum XContentType {
|
||||
|
||||
/**
|
||||
* A JSON based content type.
|
||||
*/
|
||||
JSON(0),
|
||||
/**
|
||||
* An optimized binary form of JSON.
|
||||
*/
|
||||
XSON(1);
|
||||
|
||||
public static XContentType fromRestContentType(String contentType) {
|
||||
|
|
Loading…
Reference in New Issue