我试图java.util.Date使用fastxml jackson在mongo集合中持久化一个具有字段的java对象.问题是objectMapper的默认性质是将Date存储为NumberLong类型.
例如,类型createdTime字段java.util.Date存储如下:
"createdTime" : NumberLong("1427728445176")
我想将它存储在mongo Shell中可用的ISODate格式中.
现在,我知道有办法格式化对象映射器以将日期存储在字符串dateformat中.但我只是在寻找ISODate()格式.
例如
"createdTime" : ISODate("2015-01-20T16:39:42.132Z")
有没有办法做到这一点 ?请告知大师.在此先感谢您的帮助.
x_param = openapi.Parameter('x', in_=openapi.IN_FORM, description='srring',
type=openapi.TYPE_STRING)
y_param = openapi.Parameter('y', in_=openapi.IN_FORM, description='string',
type=openapi.TYPE_STRING)
@swagger_auto_schema(method='post', manual_parameters=[x_param,y_param])
@api_view(['POST'])
def test(request):
pass
Run Code Online (Sandbox Code Playgroud)
我用作drf_yasg招摇.
我做了上面的编码并用swagger进行了测试,当我查看Chrome时,请求的有效负载是x = 124 & y = 124124.
并且,通过以下消息,发生了错误的请求错误.
{
"detail": "JSON parse error - Expecting value: line 1 column 1 (char 0)"
}
Run Code Online (Sandbox Code Playgroud)
将帖子参数添加到swagger是不对的?
我正在使用RestEasy,Jboss 7和EJB 3.1.我正在创建一个以JSON格式返回数据的RESTful Web服务.
问题是我@ManyToOne在我的一个实体上有一个关系,它会在序列化过程中导致无限递归.我尝试使用杰克逊@JsonIgnore和@JsonBackReference注释来解决这个问题,但似乎它们被完全忽略了,无限递归仍在发生.
这是我的用户类:
class User {
private String userId;
private Role role;
@Id
@Column(name = "\"UserId\"", unique = true, nullable = false, length = 30)
public String getUserId() {
return this.UserId;
}
public void setUserId(String UserId) {
this.UserId = UserId;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "\"RoleId\"", nullable = false)
//I have tried @JsonIgnore without @JsonBackReference
@JsonIgnore
//I have tried @JsonBackReference without @JsonIgnore
//Also I have tried @JsonBackReference and @JsonIgnore together …Run Code Online (Sandbox Code Playgroud)