add map conversion for Date types

This commit is contained in:
kimchy 2010-05-03 17:57:10 +03:00
parent 3ba4370477
commit 7564453fcb
2 changed files with 7 additions and 5 deletions

View File

@ -52,7 +52,7 @@ public abstract class XContentBuilder<T extends XContentBuilder> {
CAMELCASE CAMELCASE
} }
private final static DateTimeFormatter defaultDatePrinter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); public final static DateTimeFormatter defaultDatePrinter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
protected static FieldCaseConversion globalFieldCaseConversion = FieldCaseConversion.NONE; protected static FieldCaseConversion globalFieldCaseConversion = FieldCaseConversion.NONE;

View File

@ -21,12 +21,10 @@ package org.elasticsearch.util.xcontent.support;
import org.elasticsearch.util.xcontent.XContentGenerator; import org.elasticsearch.util.xcontent.XContentGenerator;
import org.elasticsearch.util.xcontent.XContentParser; import org.elasticsearch.util.xcontent.XContentParser;
import org.elasticsearch.util.xcontent.builder.XContentBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
@ -143,6 +141,10 @@ public class XContentMapConverter {
writeObjectArray(gen, (Object[]) value); writeObjectArray(gen, (Object[]) value);
} else if (type == byte[].class) { } else if (type == byte[].class) {
gen.writeBinary((byte[]) value); gen.writeBinary((byte[]) value);
} else if (type == Date.class) {
gen.writeString(XContentBuilder.defaultDatePrinter.print(((Date) value).getTime()));
} else if (type == java.sql.Date.class) {
gen.writeString(XContentBuilder.defaultDatePrinter.print(((java.sql.Date) value).getTime()));
} else { } else {
gen.writeString(value.toString()); gen.writeString(value.toString());
} }