I am having a list of entities which having various values including some string fields which i want to convert to as date.
N_year_month=20010125, N_sequence_num=1, M_sequence_num=0, N_creation_date=20010109, N_check_date=20010211, _status=H, _frequency=A, _record=0
My requirement is to convert the N_year_month,N_creation_date,N_check_date into date while returning the list.
I am posting the code i have written
DateTimeFormatter formatter_1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public List<NEntity> fetch(List<SearchCriteria> params){
CriteriaQuery<NEntity> query = getNListDetailEntityCriteriaQuery(params);
List<NEntity> nEntityDetailsList = entityManager.createQuery(query).getResultList();//in this line i am getting the data from the database
pmmEntityDetailsList.stream()
.map(i->LocalDate.parse(i.N_year_month(),formatter_1))
.collect(Collectors.toList());// Here i have tried to convert the String into date
int count = entityManager.createQuery(query).getResultList().size();
entityManager.close();
return nEntityDetailsList;
}
I have tried to convert one field into date using stream api of Java 8 , but i am having exception.My exception is below
{
"errorMessage": "Something went wrong!",
"errorDetails": "Text '20010125' could not be parsed at index 0",
"timestamp": "2021-01-06 10:29:48",
"status": 500
}
How i can convert these 3 fields N_year_month,N_creation_date,N_check_date into Date(yyyy-mm-dd format) while returning the list nEntityDetailsList;
question from:
https://stackoverflow.com/questions/65599892/how-to-convert-some-string-fields-of-a-list-of-entities-to-date-while-iterating 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…