Module org.elasticsearch.xcontent
Package org.elasticsearch.xcontent
Interface XContentBuilderExtension
public interface XContentBuilderExtension
This interface provides a way for non-JDK classes to plug in a way to serialize to xcontent.
It is greatly preferred that you implement
ToXContentFragment
in the class for encoding, however, in some situations you may not own the
class, in which case you can add an implementation here for encoding it.-
Method Summary
Modifier and TypeMethodDescriptionformatUnixEpochMillis
(long unixEpochMillis) Used to format along
representing the number of milliseconds since the Unix Epoch.Used for plugging a transformer for a date or time type object into a String (or other encodable object).Used for plugging in a human readable version of a class's encoding.Used for plugging in a generic writer for a class, for example, an example implementation:
-
Method Details
-
getXContentWriters
Map<Class<?>,XContentBuilder.Writer> getXContentWriters()Used for plugging in a generic writer for a class, for example, an example implementation:Map<Class<?>, XContentBuilder.Writer> addlWriters = new HashMap<>(); addlWriters.put(BytesRef.class, (builder, value) -> b.value(((BytesRef) value).utf8String())); return addlWriters;
- Returns:
- a map of class name to writer
-
getXContentHumanReadableTransformers
Map<Class<?>,XContentBuilder.HumanReadableTransformer> getXContentHumanReadableTransformers()Used for plugging in a human readable version of a class's encoding. It is assumed that the human readable equivalent is always behind thetoString()
method, so this transformer returns the raw value to be used. An example implementation:Map<Class<?>, XContentBuilder.HumanReadableTransformer> transformers = new HashMap<>(); transformers.put(ByteSizeValue.class, (value) -> ((ByteSizeValue) value).bytes());
- Returns:
- a map of class name to transformer used to retrieve raw value
-
getDateTransformers
Used for plugging a transformer for a date or time type object into a String (or other encodable object). For example:final DateTimeFormatter datePrinter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); Map<Class<?>, Function<Object, Object>> transformers = new HashMap<>(); transformers.put(Date.class, d -> datePrinter.print(((Date) d).getTime()));
-
formatUnixEpochMillis
Used to format along
representing the number of milliseconds since the Unix Epoch.
-