The solution is to add a local DataTime serialized configuration class, which will be transferred again when accepted
@Configuration
public class LocalDateTimeSerializerConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
return builder -> {
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer());
builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer());
};
}
/**
* Serialization
*/
public static class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
if (value != null) {
long timestamp = value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
gen.writeNumber(timestamp);
}
}
}
/**
*Deserialization
*/
public static class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext deserializationContext)
throws IOException {
long timestamp = p.getValueAsLong();
if (timestamp > 0) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
} else {
return null;
}
}
}
}
Read More:
- JSON parse error: Can not deserialize instance of java.lang.String out of START_OBJECT token
- Fuseki failed with message “Parse error: [line:1, col: 1] Content is not allowed in prolog.“
- [Solved] SyntaxError:JSON.parse:unexpected character at line 1 column 1 of the JSON data
- How to parse JSON string in.Net [error reading job object from jsonreader. Current jsonreader item is not an obj]
- [Solved] Interface automation test: JSON parse error
- [Solved] Eureka Startup Error: Root name (‘timestamp‘) does not match expected type EurekaApplications
- [Solved] JSON parse error: Unexpected character (‘‘‘ (code 39)): was expecting double-quote to star
- [Solved] JSON parse error: Unexpected character (‘‘‘ (code 39)): was expecting double-quote to start ……
- C# Error: Import “google/protobuf/timestamp.proto“ was not found or had errors. [How to Solve]
- Json: struct field readyReplicas has json tag but is not exported [How to Solve]
- [Solved] SpringBoot Error: HttpMediaTypeNotSupportedException: Content type ‘application/json‘ not supported
- [Solved] Android Error: java.lang.IllegalStateException: Not allowed to start service Intent
- [How to Fix] manual close is not allowed over a Spring managed SqlSession
- [Solved] error: Raw kernel process exited code: 3221226505
- error A2031: gisters not allowed [How to Solve]
- [Solved] Unity Error: “Not allowed to access vertices on mesh”
- [Solved] R Language Error: duplicate ‘row.names’ are not allowed
- [GO]Solve request origin not allowed by Upgrader.CheckOrigin websocket cross-domain
- There was an unexpected error (type=Method Not Allowed, status=405). Request
- [Solved] Parsing JSON error unexpected end of JSON input