小编Gha*_*ada的帖子

如何在MongoDb中使用jackson将Date字段存储为ISODate()

我试图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")

有没有办法做到这一点 ?请告知大师.在此先感谢您的帮助.

java mongodb jackson

16
推荐指数
2
解决办法
2万
查看次数

django rest framework - 如何将帖子参数添加到api文档(drf_yasg)?

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是不对的?

django swagger django-rest-framework drf-yasg

11
推荐指数
1
解决办法
1525
查看次数

@JsonIgnore和@JsonBackReference被忽略了

我正在使用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)

json resteasy jackson ejb-3.1 jboss7.x

6
推荐指数
3
解决办法
1万
查看次数