I am trying to Map object Datetime
to Date
Datatype here is my code:-
HolidayResponse holidayResponse=null;
app=(HrmsApp)context.getApplicationContext();
HttpClient client = new DefaultHttpClient();
String Year=app.getHolidayYear();
SettingsManager settings = new SettingsManager(context);
String AuthenticationToken=app.getAuthenticationToken();
HttpGet request=new HttpGet(settings.GetHolidayUrl(Year));
HttpResponse response;
HttpEntity entity=null;
try{
request.setHeader("ApplicationToken",AuthenticationToken);
response = client.execute(request);
entity = response.getEntity();
if (entity != null) {
InputStream inStream = entity.getContent();
String s = CommonTasks.convertStreamToString(inStream);
GsonBuilder gsonb = new GsonBuilder();
DateDeserializer ds = new DateDeserializer();
gsonb.registerTypeAdapter(Date.class, ds);
Gson gson = gsonb.create();
Type jsonResponseType = new TypeToken<ArrayList<Holiday>>() {
}.getType();
List<Holiday> holidayList= gson.fromJson(s,jsonResponseType);//Here i am mapping the Value getting through json into Holiday
}
}catch (Exception e) {
e.printStackTrace();
}
Here is My Holiday Class
public class Holiday {
public String Name;
public String Description;
public Date Holidaydate;
public Holiday()
{}
}
My Json Result Sample
[{"Name":"New Year's Day","Description":"New Year's Day","Holidaydate":"2014-01-01T00:00:00"}]
i am trying to map Holidaydate
from Json result to Holiday Class Holidaydate
Property which is Date
type.
I am not getting how to parse datetime to date at the time of mapping.
is there anyway then tell me thanks in advance.