Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
examsAndAdmissions
Commits
b7b959a4
Commit
b7b959a4
authored
1 year ago
by
Radheshhathwar
Browse files
Options
Download
Patches
Plain Diff
Bulk upload for attendance and result
parent
91ddb8b9
uri_access_check
Response_fixes
auxillary_apis
bug_fix_question_paper_upload
development
fee_changes
fee_workflow
github/fork/ruksana2808/filter_bug_examCycle
instituteApis_shishir
1 merge request
!40
Bulk upload for attendance and result
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/AttendanceController.java
+45
-0
...f/examsAndAdmissions/controller/AttendanceController.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/StudentResultController.java
+44
-8
...xamsAndAdmissions/controller/StudentResultController.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/AttendanceRecord.java
+37
-2
...ento/upsmf/examsAndAdmissions/model/AttendanceRecord.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/StudentResult.java
+30
-4
...tarento/upsmf/examsAndAdmissions/model/StudentResult.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/ResultRepository.java
+8
-8
...upsmf/examsAndAdmissions/repository/ResultRepository.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/service/DataImporterService.java
+87
-3
...upsmf/examsAndAdmissions/service/DataImporterService.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/util/CustomDateDeserializer.java
+23
-0
...upsmf/examsAndAdmissions/util/CustomDateDeserializer.java
src/main/java/com/tarento/upsmf/examsAndAdmissions/util/CustomDateSerializer.java
+17
-0
...o/upsmf/examsAndAdmissions/util/CustomDateSerializer.java
with
291 additions
and
25 deletions
+291
-25
src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/AttendanceController.java
+
45
−
0
View file @
b7b959a4
...
...
@@ -2,14 +2,20 @@ package com.tarento.upsmf.examsAndAdmissions.controller;
import
com.tarento.upsmf.examsAndAdmissions.enums.ApprovalStatus
;
import
com.tarento.upsmf.examsAndAdmissions.model.AttendanceRecord
;
import
com.tarento.upsmf.examsAndAdmissions.repository.AttendanceRepository
;
import
com.tarento.upsmf.examsAndAdmissions.service.AttendanceService
;
import
com.tarento.upsmf.examsAndAdmissions.service.DataImporterService
;
import
com.tarento.upsmf.examsAndAdmissions.util.Constants
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@RestController
@RequestMapping
(
"/api/v1/attendance"
)
...
...
@@ -18,6 +24,11 @@ public class AttendanceController {
@Autowired
private
AttendanceService
attendanceService
;
@Autowired
private
DataImporterService
dataImporterService
;
@Autowired
AttendanceRepository
repository
;
@PostMapping
(
"/upload"
)
public
ResponseEntity
<
String
>
uploadAttendanceFile
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
if
(
file
.
isEmpty
())
{
...
...
@@ -61,4 +72,38 @@ public class AttendanceController {
return
ResponseEntity
.
ok
(
"Student rejected successfully with reason: "
+
reason
);
}
@PostMapping
(
"/bulkUpload"
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
processBulkAttendanceUpload
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
"fileType"
)
String
fileType
)
{
Map
<
String
,
Object
>
response
=
new
HashMap
<>();
JSONArray
jsonArray
=
null
;
Class
<
AttendanceRecord
>
dtoClass
=
AttendanceRecord
.
class
;
try
{
switch
(
fileType
.
toLowerCase
())
{
case
Constants
.
CSV
:
jsonArray
=
dataImporterService
.
csvToJson
(
file
);
break
;
case
Constants
.
EXCEL
:
jsonArray
=
dataImporterService
.
excelToJson
(
file
);
break
;
default
:
// Handle unsupported file type
response
.
put
(
"error"
,
"Unsupported file type"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
response
);
}
List
<
AttendanceRecord
>
dtoList
=
dataImporterService
.
convertJsonToDtoList
(
jsonArray
,
AttendanceRecord
.
class
);
Boolean
success
=
dataImporterService
.
saveDtoListToPostgres
(
dtoList
,
repository
);
if
(
success
)
{
response
.
put
(
"message"
,
"File processed successfully."
);
return
ResponseEntity
.
ok
(
response
);
}
else
{
response
.
put
(
"error"
,
"File processing failed."
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
response
);
}
}
catch
(
Exception
e
)
{
response
.
put
(
"error"
,
"An error occurred while processing the file: "
+
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
response
);
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/controller/StudentResultController.java
+
44
−
8
View file @
b7b959a4
package
com.tarento.upsmf.examsAndAdmissions.controller
;
import
com.tarento.upsmf.examsAndAdmissions.model.RetotallingRequest
;
import
com.tarento.upsmf.examsAndAdmissions.model.Student
;
import
com.tarento.upsmf.examsAndAdmissions.model.Exam
;
import
com.tarento.upsmf.examsAndAdmissions.model.StudentResult
;
import
com.tarento.upsmf.examsAndAdmissions.model.*
;
import
com.tarento.upsmf.examsAndAdmissions.model.dao.Payment
;
import
com.tarento.upsmf.examsAndAdmissions.repository.AttendanceRepository
;
import
com.tarento.upsmf.examsAndAdmissions.repository.ResultRepository
;
import
com.tarento.upsmf.examsAndAdmissions.service.DataImporterService
;
import
com.tarento.upsmf.examsAndAdmissions.service.RetotallingService
;
import
com.tarento.upsmf.examsAndAdmissions.service.StudentResultService
;
import
com.tarento.upsmf.examsAndAdmissions.service.StudentService
;
import
com.tarento.upsmf.examsAndAdmissions.util.Constants
;
import
lombok.extern.slf4j.Slf4j
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -20,9 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.*
;
@RestController
@RequestMapping
(
"/api/v1/studentResults"
)
...
...
@@ -36,7 +36,10 @@ public class StudentResultController {
private
RetotallingService
retotallingService
;
@Autowired
private
StudentService
studentService
;
@Autowired
private
DataImporterService
dataImporterService
;
@Autowired
ResultRepository
repository
;
@PostMapping
(
"/upload/internal"
)
public
ResponseEntity
<
String
>
uploadInternalMarks
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
try
{
...
...
@@ -160,4 +163,37 @@ public class StudentResultController {
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Failed to update results."
);
}
}
@PostMapping
(
"/bulkUpload"
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
processBulkResultUpload
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
"fileType"
)
String
fileType
)
{
Map
<
String
,
Object
>
response
=
new
HashMap
<>();
JSONArray
jsonArray
=
null
;
Class
<
StudentResult
>
dtoClass
=
StudentResult
.
class
;
try
{
switch
(
fileType
.
toLowerCase
())
{
case
Constants
.
CSV
:
jsonArray
=
dataImporterService
.
csvToJson
(
file
);
break
;
case
Constants
.
EXCEL
:
jsonArray
=
dataImporterService
.
excelToJson
(
file
);
break
;
default
:
// Handle unsupported file type
response
.
put
(
"error"
,
"Unsupported file type"
);
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
).
body
(
response
);
}
List
<
StudentResult
>
dtoList
=
dataImporterService
.
convertJsonToDtoList
(
jsonArray
,
StudentResult
.
class
);
Boolean
success
=
dataImporterService
.
saveDtoListToPostgres
(
dtoList
,
repository
);
if
(
success
)
{
response
.
put
(
"message"
,
"File processed successfully."
);
return
ResponseEntity
.
ok
(
response
);
}
else
{
response
.
put
(
"error"
,
"File processing failed."
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
response
);
}
}
catch
(
Exception
e
)
{
response
.
put
(
"error"
,
"An error occurred while processing the file: "
+
e
.
getMessage
());
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
response
);
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/AttendanceRecord.java
+
37
−
2
View file @
b7b959a4
package
com.tarento.upsmf.examsAndAdmissions.model
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
import
com.tarento.upsmf.examsAndAdmissions.enums.ApprovalStatus
;
import
lombok.*
;
import
com.tarento.upsmf.examsAndAdmissions.util.CustomDateDeserializer
;
import
com.tarento.upsmf.examsAndAdmissions.util.CustomDateSerializer
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
javax.persistence.*
;
import
java.time.LocalDate
;
import
java.util.Date
;
@Entity
...
...
@@ -18,18 +25,32 @@ public class AttendanceRecord {
@Id
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
@JsonProperty
(
"First Name"
)
private
String
firstName
;
@JsonProperty
(
"Last Name"
)
private
String
lastName
;
@Column
(
unique
=
true
)
@JsonProperty
(
"Enrolment Number"
)
private
String
studentEnrollmentNumber
;
@JsonProperty
(
"Mother's Name"
)
private
String
mothersName
;
@JsonProperty
(
"Father's Name"
)
private
String
fathersName
;
@JsonProperty
(
"Course"
)
private
String
courseName
;
@ManyToOne
(
fetch
=
FetchType
.
LAZY
)
@JoinColumn
(
name
=
"exam_cycle_id"
)
private
ExamCycle
examCycle
;
@JsonProperty
(
"Exam Cycle"
)
private
String
examCycleData
;
@JsonProperty
(
"Start Date"
)
@JsonSerialize
(
using
=
CustomDateSerializer
.
class
)
@JsonDeserialize
(
using
=
CustomDateDeserializer
.
class
)
private
Date
startDate
;
@JsonProperty
(
"End Date"
)
@JsonSerialize
(
using
=
CustomDateSerializer
.
class
)
@JsonDeserialize
(
using
=
CustomDateDeserializer
.
class
)
private
Date
endDate
;
private
int
totalDays
;
private
int
present
;
...
...
@@ -37,6 +58,13 @@ public class AttendanceRecord {
private
String
rejectionReason
;
@Enumerated
(
EnumType
.
STRING
)
private
ApprovalStatus
approvalStatus
=
ApprovalStatus
.
PENDING
;
@JsonProperty
(
"Number of Working Days"
)
private
int
numberOfWorkingDays
;
@JsonProperty
(
"Present Days"
)
private
int
presentDays
;
@JsonProperty
(
"Absent Days"
)
private
int
absentDays
;
@JsonProperty
(
"Attendance Percentage"
)
private
double
attendancePercentage
;
// Calculate attendance percentage before saving to DB
@PrePersist
...
...
@@ -44,4 +72,11 @@ public class AttendanceRecord {
public
void
calculateAttendancePercentage
()
{
this
.
attendancePercentage
=
(
double
)
(
this
.
present
*
100
)
/
this
.
totalDays
;
}
public
void
setNumberOfWorkingDays
(
int
numberOfWorkingDays
)
{
this
.
numberOfWorkingDays
=
numberOfWorkingDays
;
}
public
void
setAttendancePercentage
(
double
attendancePercentage
)
{
this
.
attendancePercentage
=
attendancePercentage
;
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/model/StudentResult.java
+
30
−
4
View file @
b7b959a4
package
com.tarento.upsmf.examsAndAdmissions.model
;
import
com.fasterxml.jackson.annotation.JsonProperty
;
import
com.tarento.upsmf.examsAndAdmissions.enums.ResultStatus
;
import
lombok.*
;
...
...
@@ -20,25 +21,43 @@ public class StudentResult {
@GeneratedValue
(
strategy
=
GenerationType
.
IDENTITY
)
private
Long
id
;
// Associations with Student entity
@ManyToOne
@JoinColumn
(
name
=
"student_id"
)
private
Student
student
;
// New Fields
private
String
firstName
;
private
String
lastName
;
private
String
enrollmentNumber
;
private
String
motherName
;
private
String
fatherName
;
// Associations with Course, ExamCycle, and Exam entities
@ManyToOne
@JoinColumn
(
name
=
"course_id"
)
private
Course
course
;
@JsonProperty
(
"Course"
)
private
String
courseValue
;
@ManyToOne
@JoinColumn
(
name
=
"exam_cycle_id"
)
private
ExamCycle
examCycle
;
@JsonProperty
(
"Exam Cycle"
)
private
String
examCycleValue
;
@ManyToOne
@JoinColumn
(
name
=
"exam_id"
)
private
Exam
exam
;
@JsonProperty
(
"Exam"
)
private
String
examValue
;
// Fields from your previous message
private
BigDecimal
internalMarks
;
private
BigDecimal
passingInternalMarks
;
private
BigDecimal
internalMarksObtained
;
private
BigDecimal
externalMarks
;
private
BigDecimal
passingExternalMarks
;
private
BigDecimal
externalMarksObtained
;
private
BigDecimal
practicalMarks
;
private
BigDecimal
passingPracticalMarks
;
private
BigDecimal
practicalMarksObtained
;
...
...
@@ -47,12 +66,19 @@ public class StudentResult {
private
BigDecimal
passingOtherMarks
;
private
BigDecimal
otherMarksObtained
;
private
BigDecimal
externalMarks
;
private
BigDecimal
passingExternalMarks
;
private
BigDecimal
externalMarksObtained
;
private
BigDecimal
totalMarks
;
private
BigDecimal
passingTotalMarks
;
private
BigDecimal
totalMarksObtained
;
private
String
grade
;
private
String
result
;
@Enumerated
(
EnumType
.
STRING
)
private
ResultStatus
status
=
ResultStatus
.
ENTERED
;
private
boolean
published
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/repository/ResultRepository.java
+
8
−
8
View file @
b7b959a4
/*
package
com.tarento.upsmf.examsAndAdmissions.repository
;
import
com.tarento.upsmf.examsAndAdmissions.model.StudentResult
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.stereotype.Repository
;
@Repository
public interface ResultRepository extends JpaRepository<Result, Long> {
Result findByEnrollmentNumberAndDob(String enrolmentNumber, String dob);
List<Result> findByStudentId(Long studentId);
}
import
java.util.List
;
@Repository
public
interface
ResultRepository
extends
JpaRepository
<
StudentResult
,
Long
>
{
StudentResult
findByEnrollmentNumber
(
String
enrollmentNumber
);
*/
List
<
StudentResult
>
findByStudentId
(
Long
studentId
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/service/DataImporterService.java
+
87
−
3
View file @
b7b959a4
package
com.tarento.upsmf.examsAndAdmissions.service
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.tarento.upsmf.examsAndAdmissions.model.AttendanceRecord
;
import
com.tarento.upsmf.examsAndAdmissions.model.ExamUploadData
;
import
com.tarento.upsmf.examsAndAdmissions.repository.ExamCycleRepository
;
import
com.tarento.upsmf.examsAndAdmissions.model.StudentResult
;
import
com.tarento.upsmf.examsAndAdmissions.repository.AttendanceRepository
;
import
com.tarento.upsmf.examsAndAdmissions.repository.ExamEntityRepository
;
import
com.tarento.upsmf.examsAndAdmissions.repository.ResultRepository
;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVParser
;
import
org.apache.commons.csv.CSVRecord
;
...
...
@@ -114,14 +117,32 @@ public class DataImporterService {
public
Boolean
saveDtoListToPostgres
(
List
<
ExamUploadData
>
dtoList
,
ExamEntityRepository
repository
)
{
try
{
List
<
ExamUploadData
>
entityList
=
convertDtoListToEntities
(
dtoList
);
List
<
ExamUploadData
>
entityList
=
convert
Exam
DtoListToEntities
(
dtoList
);
repository
.
saveAll
(
entityList
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
private
List
<
ExamUploadData
>
convertDtoListToEntities
(
List
<
ExamUploadData
>
dtoList
)
{
public
Boolean
saveDtoListToPostgres
(
List
<
AttendanceRecord
>
dtoList
,
AttendanceRepository
repository
)
{
try
{
List
<
AttendanceRecord
>
entityList
=
convertAttendenceDtoListToEntities
(
dtoList
);
repository
.
saveAll
(
entityList
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
public
Boolean
saveDtoListToPostgres
(
List
<
StudentResult
>
dtoList
,
ResultRepository
repository
)
{
try
{
List
<
StudentResult
>
entityList
=
convertResultDtoListToEntities
(
dtoList
);
repository
.
saveAll
(
entityList
);
return
true
;
}
catch
(
Exception
e
)
{
return
false
;
}
}
private
List
<
ExamUploadData
>
convertExamDtoListToEntities
(
List
<
ExamUploadData
>
dtoList
)
{
List
<
ExamUploadData
>
entityList
=
new
ArrayList
<>();
for
(
ExamUploadData
dto
:
dtoList
)
{
...
...
@@ -144,4 +165,67 @@ public class DataImporterService {
return
entityList
;
}
private
List
<
AttendanceRecord
>
convertAttendenceDtoListToEntities
(
List
<
AttendanceRecord
>
dtoList
)
{
List
<
AttendanceRecord
>
entityList
=
new
ArrayList
<>();
for
(
AttendanceRecord
dto
:
dtoList
)
{
AttendanceRecord
entity
=
new
AttendanceRecord
();
entity
.
setFirstName
(
dto
.
getFirstName
());
entity
.
setLastName
(
dto
.
getLastName
());
entity
.
setStudentEnrollmentNumber
(
dto
.
getStudentEnrollmentNumber
());
entity
.
setMothersName
(
dto
.
getMothersName
());
entity
.
setFathersName
(
dto
.
getFathersName
());
entity
.
setCourseName
(
dto
.
getCourseName
());
entity
.
setExamCycleData
(
dto
.
getExamCycleData
());
entity
.
setStartDate
(
dto
.
getStartDate
());
entity
.
setEndDate
(
dto
.
getEndDate
());
entity
.
setNumberOfWorkingDays
(
dto
.
getNumberOfWorkingDays
());
entity
.
setPresentDays
(
dto
.
getPresentDays
())
;
entity
.
setAbsentDays
(
dto
.
getAbsentDays
());
entity
.
setAttendancePercentage
(
dto
.
getAttendancePercentage
());
entityList
.
add
(
entity
);
}
return
entityList
;
}
private
List
<
StudentResult
>
convertResultDtoListToEntities
(
List
<
StudentResult
>
dtoList
)
{
List
<
StudentResult
>
entityList
=
new
ArrayList
<>();
for
(
StudentResult
dto
:
dtoList
)
{
StudentResult
entity
=
new
StudentResult
();
entity
.
setFirstName
(
dto
.
getFirstName
());
entity
.
setLastName
(
dto
.
getLastName
());
entity
.
setEnrollmentNumber
(
dto
.
getEnrollmentNumber
());
entity
.
setMotherName
(
dto
.
getMotherName
());
entity
.
setFatherName
(
dto
.
getFatherName
());
entity
.
setCourseValue
(
dto
.
getCourseValue
());
entity
.
setExamCycleValue
(
dto
.
getExamCycleValue
());
entity
.
setExamValue
(
dto
.
getExamValue
());
entity
.
setInternalMarks
(
dto
.
getInternalMarks
());
entity
.
setPassingInternalMarks
(
dto
.
getPassingInternalMarks
());
entity
.
setInternalMarksObtained
(
dto
.
getInternalMarksObtained
());
;
entity
.
setPracticalMarks
(
dto
.
getPracticalMarks
());
entity
.
setPassingPracticalMarks
(
dto
.
getPassingPracticalMarks
());
entity
.
setPracticalMarksObtained
(
dto
.
getPracticalMarksObtained
());
;
entity
.
setOtherMarks
(
dto
.
getOtherMarks
());
entity
.
setPassingOtherMarks
(
dto
.
getPassingOtherMarks
());
entity
.
setOtherMarksObtained
(
dto
.
getOtherMarksObtained
());
;
entity
.
setExternalMarks
(
dto
.
getExternalMarks
());
entity
.
setPassingExternalMarks
(
dto
.
getPassingExternalMarks
());
entity
.
setExternalMarksObtained
(
dto
.
getExternalMarksObtained
());
entity
.
setTotalMarks
(
dto
.
getTotalMarks
());
entity
.
setPassingTotalMarks
(
dto
.
getPassingTotalMarks
());
entity
.
setTotalMarksObtained
(
dto
.
getTotalMarksObtained
());
entity
.
setGrade
(
dto
.
getGrade
());
entity
.
setResult
(
dto
.
getResult
());
entityList
.
add
(
entity
);
}
return
entityList
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/util/CustomDateDeserializer.java
0 → 100644
+
23
−
0
View file @
b7b959a4
package
com.tarento.upsmf.examsAndAdmissions.util
;
import
com.fasterxml.jackson.core.JsonParser
;
import
com.fasterxml.jackson.databind.DeserializationContext
;
import
com.fasterxml.jackson.databind.JsonDeserializer
;
import
java.io.IOException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
public
class
CustomDateDeserializer
extends
JsonDeserializer
<
Date
>
{
private
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"EEE MMM dd HH:mm:ss zzz yyyy"
);
@Override
public
Date
deserialize
(
JsonParser
jsonParser
,
DeserializationContext
deserializationContext
)
throws
IOException
{
String
dateStr
=
jsonParser
.
getText
();
try
{
return
dateFormat
.
parse
(
dateStr
);
}
catch
(
ParseException
e
)
{
throw
new
IOException
(
"Failed to parse date: "
+
dateStr
,
e
);
}
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/examsAndAdmissions/util/CustomDateSerializer.java
0 → 100644
+
17
−
0
View file @
b7b959a4
package
com.tarento.upsmf.examsAndAdmissions.util
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
public
class
CustomDateSerializer
extends
JsonSerializer
<
Date
>
{
private
final
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"EEE MMM dd HH:mm:ss zzz yyyy"
);
@Override
public
void
serialize
(
Date
date
,
JsonGenerator
jsonGenerator
,
SerializerProvider
serializerProvider
)
throws
IOException
{
jsonGenerator
.
writeString
(
dateFormat
.
format
(
date
));
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets