ESジェストを使用しています。検索して回答を得ることができます。しかし、Date
プロパティでシリアル化を行うと、シリアル化null
後に応答が得られました。
以下は、ES ドキュメント インデックスと検索結果のクラスです。
public class IndexDocument {
public long id;
@JsonSerialize(using = JsonDateSerializer.class)
public Date Date1;
@JsonSerialize(using = JsonDateSerializer.class)
public Date Date2;
}
日付のシリアル化には次のコードがあります。
public class JsonDateSerializer extends JsonSerializer<Date> {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss.SSSZ");
@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonProcessingException {
String formattedDate = dateFormat.format(date);
gen.writeString(formattedDate);
}
}
ES からの応答:
"hits" : [{
"_index" : "myindex",
"_type" : "mytype",
"_id" : "3",
"_score" : 1.3294203,
"_source" : {
"Date1" : "2016-11-24T14:39:08.000Z",
"id" : 1,
"Date2" : "1900-01-01T00:00:00.000Z"
}
}
]
私のシリアル化コード:
JestResult result = client.execute(search); // i can see the response here
response = result.getSourceAsObjectList(IndexDocument.class);
連載後、私はresponse = null
から日付プロパティを削除するとindexDocument
、シリアル化された応答が表示されます。ただし、日付プロパティでは機能しません。何が悪かったのか?