I need to persist object in Azure Table Storage . Problem is I don't want to use Date type in my Entity class. I would like to use Instant but I have problems with parsing with the JasonMappingException
.
Here is my entity class:
@Data
public class Event extends TableServiceEntity {
@NotNull
@JsonDeserialize(using = JsonDateDeserializer.class)
private Instant eventStart;
@NotNull
@JsonDeserialize(using = JsonDateDeserializer.class)
private Instant eventEnd;
@NotBlank
private String eventName;
private String eventDescription;
//default constructor
public Event () {}
}
And here is my deserializer:
public class JsonDateDeserializer extends JsonDeserializer<Instant> {
@Override
public Instant deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
String date = jsonParser.getText();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
try {
return sdf.parse(date).toInstant();
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}
I am getting this error:
2020-06-10 20:47:19.685 WARN 11745 --- [nio-8080-exec-1].wsmsDefaultHandlerExceptionResolver: Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: java.text.ParseException: Unparseable date: "2020-06-12T08:00:00UTC"; nested exception is com.fasterxml.jackson.databind.JsonMappingException: java.text.ParseException: Unparseable date: "2020-06-12T08:00:00UTC" (through reference chain: com.komix.eventmanager.model.Event["eventStart"])]
I am soo tired of the date problems with Azure DB. Could you please help me?
EDIT: Ok, after some edit parsing is fine but application gives me following error:
java.lang.IllegalArgumentException: Type class java.time.Instant is not supported.
It seems that Azure Table Storage doesn't support Instant??. I can't even find any good documentation for Asure Table data types supported...
'Z'
is considered here as constants. You need to pass z
without the quotes.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssz");
Doc ref here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.