# Dealing with date types in Java API

**URL:** <https://discuss.elastic.co/t/dealing-with-date-types-in-java-api/14569>\
**Category:** Elasticsearch\
**Created:** [November 24, 2013, 9:07pm UTC](https://discuss.elastic.co/t/dealing-with-date-types-in-java-api/14569 "2013-11-24T21:07:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jan\_Hendrik\_Lendholt](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@Jan\_Hendrik\_Lendholt](https://discuss.elastic.co/u/Jan_Hendrik_Lendholt)\
**Post date:** [November 24, 2013, 9:07pm UTC](https://discuss.elastic.co/t/dealing-with-date-types-in-java-api/14569/1 "2013-11-24T21:07:51Z")

</div>

Hi there,

I am dealing with the Java API and have a problem getting a Date object  
back.

For the index /employees/employee I have a mapping for the employed\_since  
field like:

"employed\_since": {  
"type": "date",  
"format": "dateOptionalTime"  
}  
The document has of course some more fields 🙂

With the Java-API I created a node and I'll issue a:

GetResponse object = client.prepareGet("employees", "employee",  
"SOME\_ID").setFields("employed\_since", "name", "first\_name", "gender"  
).execute().actionGet();

When I now try to access object.getField("employed\_since").getValue() I  
receive the String representation of the Date object.

of course I could parse the string, but what is the best practice here? How  
do I get the Date object back without having to parse it?

Thanks for any help!

Jan

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Pacer\_Girl](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@Pacer\_Girl](https://discuss.elastic.co/u/Pacer_Girl)\
**Post date:** [February 23, 2017, 7:36pm UTC](https://discuss.elastic.co/t/dealing-with-date-types-in-java-api/14569/2 "2017-02-23T19:36:20Z")

</div>

Has anyone responded to your initial post...I know that it has been an few years

I am running into this same issue and wanted to know if there was like a unmarshall like functionality I can hook into that will convert the String Date into an actual Date object.

I will also try to re-post in case.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:02pm UTC](https://discuss.elastic.co/t/dealing-with-date-types-in-java-api/14569/3 "2017-07-05T22:02:56Z")

</div>


