LocalTime truncating trailing 00 values

112 Views Asked by At

The original time value stored in my cassandra DB is : 11:43:00.000000000

I am trying to fetch it in my JSON response as : 11:43:00

What I am getting is: 11:43

What I have tried so far in my model class:

import java.time.LocalTime;
@Getter @Setter @RequiredArgsConstructor @AllArgsConstructor
public class Test {
...
@JsonFormat(pattern="HH:mm:ss")
private LocalTime delgtexpytm;

AND

@JsonFormat(pattern="KK:mm:ss")
private LocalTime delgtexpytm;

But both of them are trimming the trailing 00.

1

There are 1 best solutions below

2
Nikolas Charalambidis On

Untested

Try to override the shape property to STRING to specify the JSON type to be used. I guess it should help as long as the following explanation from the JavaDoc for the shape:

Structure to use for serialization: definition of mapping depends on datatype, but usually has straight-forward counterpart in data format (JSON).

@JsonFormat(pattern="HH:mm:ss", shape=JsonFormat.Shape.STRING)
private LocalTime delgtexpytm;