我需要在远程服务上发送更新请求以更新某些字段。远程服务使用application/json
内容类型,所以我实现了我的休息客户端,如:
@RegisterRestClient
@Path("/api/v1")
@Produces("application/json")
@Consumes("application/json")
@ApplicationScoped
public interface ServiceClient {
@POST
@Path("/path_to_update/{uuid}")
Response updateAttributes(
@PathParam("uuid") String uuid,
Attributes attributes
);
}
@NoArgsConstructor
@Data
@AllArgsConstructor
@Builder
public class Attributes {
private AttributesA a;
private AttributesB b;
}
@NoArgsConstructor
@Data
@AllArgsConstructor
@Builder
public class AttributesA {
private String field1;
}
@NoArgsConstructor
@Data
@AllArgsConstructor
@Builder
public class AttributesB {
private String field2;
private String field3;
}
我只需要更新字段的一个子集。也许field1
和field3
。所以在这种情况下field2
将被设置为null
。
远程服务不接受 anull
作为参数值,因此我需要避免序列化所有具有null
值的字段。
我的项目使用jsonb
并且我已经尝试注释模型类JsonbNillable
但没有任何成功。
是否有办法配置其余客户端以避免空字段的序列化?