Azure functions Spring云函数azure json输出,带有日期时间
我从一个azure函数输出一个POJO,该函数是用SpringCloud函数编写的,它包含一个datetime类型。我用instant试用过,它被视为POJO:Azure functions Spring云函数azure json输出,带有日期时间,azure-functions,azure-function-app,spring-cloud-function,Azure Functions,Azure Function App,Spring Cloud Function,我从一个azure函数输出一个POJO,该函数是用SpringCloud函数编写的,它包含一个datetime类型。我用instant试用过,它被视为POJO: "timestamp": { "seconds": 1584229103, "nanos" 0 } 我尝试将其作为OffsetDateTime并得到: "timestamp": { "dateTime": { "date": { "year": 1970,
"timestamp": {
"seconds": 1584229103,
"nanos" 0
}
我尝试将其作为OffsetDateTime并得到:
"timestamp": {
"dateTime": {
"date": {
"year": 1970,
"month": 1,
"day": 19
},
"time": {
"hour": 8,
"minute": 3,
"second": 46,
"nano": 837000000
}
},
"offset": {
"totalSeconds": 0
}
}
我在春季尝试了各种方法,比如:
@Bean
public MappingJackson2MessageConverter configJacksonMessageConverter() {
final MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new JavaTimeModule());
mappingJackson2MessageConverter.setObjectMapper(objectMapper);
return mappingJackson2MessageConverter;
}
但它们没有效果。阅读它听起来像是azure functions java worker正在做将pojo转换为json的最后工作,而它根本没有使用jackson。
如何通过自动序列化值获得类似于JavaTimeModule的输出?我必须使用字符串输出吗?
我找不到有关这方面的文档,也找不到示例。不幸的是,有好几个层次
- spring云函数使用jackson(默认情况下正确处理java.time.*)
- 目前被窃听
- 使用gson的azure函数运行时(azure函数java worker)
- 目前被窃听
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
public class InstantGsonAdapter extends TypeAdapter<Instant> {
@Override
public void write(JsonWriter out, Instant value) throws IOException {
out.value(DateTimeFormatter.ISO_INSTANT.format(value));
}
@Override
public Instant read(JsonReader in) throws IOException {
return Instant.parse(in.nextString());
}
}
import com.google.gson.TypeAdapter;
导入com.google.gson.stream.JsonReader;
导入com.google.gson.stream.JsonWriter;
导入java.io.IOException;
导入java.time.Instant;
导入java.time.format.DateTimeFormatter;
公共类InstantgSonaAdapter扩展了TypeAdapter{
@凌驾
公共void write(JsonWriter out,即时值)抛出IOException{
out.value(DateTimeFormatter.ISO_INSTANT.format(value));
}
@凌驾
公共即时读取(JsonReader in)引发IOException{
返回Instant.parse(在.nextString()中);
}
}
但它停止了工作。。。我还没有调查为什么。。。可能是因为我试图修复/解决另一层的另一个bug。还是因为我昨天升级了
小贴士:小心你在测试什么。。。是否运行Spring云函数应用程序并调用它。或者运行azure运行时(mvn azure函数:run)并调用它。。。通常,spring测试调用第一个
(我将尝试查找并发布相关的bug…抱歉,我现在无法发布)不幸的是,有几个层
- spring云函数使用jackson(默认情况下正确处理java.time.*)
- 目前被窃听
- 使用gson的azure函数运行时(azure函数java worker)
- 目前被窃听
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
public class InstantGsonAdapter extends TypeAdapter<Instant> {
@Override
public void write(JsonWriter out, Instant value) throws IOException {
out.value(DateTimeFormatter.ISO_INSTANT.format(value));
}
@Override
public Instant read(JsonReader in) throws IOException {
return Instant.parse(in.nextString());
}
}
import com.google.gson.TypeAdapter;
导入com.google.gson.stream.JsonReader;
导入com.google.gson.stream.JsonWriter;
导入java.io.IOException;
导入java.time.Instant;
导入java.time.format.DateTimeFormatter;
公共类InstantgSonaAdapter扩展了TypeAdapter{
@凌驾
公共void write(JsonWriter out,即时值)抛出IOException{
out.value(DateTimeFormatter.ISO_INSTANT.format(value));
}
@凌驾
公共即时读取(JsonReader in)引发IOException{
返回Instant.parse(在.nextString()中);
}
}
但它停止了工作。。。我还没有调查为什么。。。可能是因为我试图修复/解决另一层的另一个bug。还是因为我昨天升级了
小贴士:小心你在测试什么。。。是否运行Spring云函数应用程序并调用它。或者运行azure运行时(mvn azure函数:run)并调用它。。。通常,spring测试调用第一个
(我将尝试查找并发布相关错误…我现在无法,抱歉)