【发布时间】:2021-05-25 20:51:35
【问题描述】:
如何在 MicroProfile Rest Client 使用的 Json Serializer 上设置特定格式的表示?
我有一项服务需要输入年月数据,格式为 ISO 8601“YYYY-MM”。服务器端工作正常,响应格式正确,但实现是 Resteasy。
我使用的是 MicroProfile Rest Client,实体属性定义为java.util.YearMonth。
当我希望它是格式化字符串时,请求使用序列化的 JSON 年月属性表示为对象。
已尝试使用JsonFormat、JsonbDateFormat 和@Schema 注释属性,结果相同。
还尝试添加适用于服务器端的 Jackson Provider (ContextResolver),但在客户端没有任何变化。
睾丸注释的代码sn-p:
import com.fasterxml.jackson.annotation.JsonFormat;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import javax.json.bind.annotation.JsonbDateFormat;
@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM")
@JsonbDateFormat(value = "yyyy-MM")
// Next one I'm guessing. Can't find docs for this.
@Schema(type = SchemaType.STRING, implementation = YearMonth.class, pattern = "yyyy-MM")
private YearMonth referencia;
环境:
- 野蝇 21
- Java SE 11
- microprofile-rest-client-api:2.0
- microprofile-openapi-api:2.0
【问题讨论】:
标签: java json rest microprofile