将mongodb集合映射到不存在的java类

时间:2016-02-05 14:38:04

标签: java json spring mongodb

我有一个包含多个集合的mongodb,我需要使用spring将这些集合映射到新的Java类。第一个想法是期望一个项目作为json并基于此json代码生成java类。这是json:

{


    "_id" : ObjectId("5550b632e6d665c6fc8b4567"), 
    "id" : NumberInt(1), 
    "registrationDate" : "2008-11-02 10:55:05", 
    "firstname" : "", 
    "lastname" : "", 
    "email" : "mail@mail.nl", 
    "salutation" : "", 
    "enabled" : false, 
    "bounceCount" : NumberInt(0), 
    "groups" : [
        NumberInt(1), 
        NumberInt(15), 
        NumberInt(16), 
        NumberInt(19), 
        NumberInt(20), 
        NumberInt(21), 
        NumberInt(22)
    ], 
    "tags" : [
        NumberInt(1), 
        NumberInt(19), 
        NumberInt(29), 
        NumberInt(34), 
        NumberInt(49), 
        NumberInt(51), 
        NumberInt(68), 
        NumberInt(89), 
        NumberInt(547), 
        NumberInt(568), 
        NumberInt(569), 
        NumberInt(571)
    ], 
    "identifier" : "s47FOeqYzUt7xENFKPIkZwKc5LtrYrcL", 
    "orders" : [
        {
            "langIndependentId" : NumberInt(39), 
            "orderDate" : NumberInt(1279584917), 
            "updatePeriod" : NumberInt(1342821599), 
            "amounteur" : NumberInt(1989)
        }, 
        {
            "langIndependentId" : NumberInt(41), 
            "orderDate" : NumberInt(1279623009), 
            "updatePeriod" : NumberInt(1405893599), 
            "amounteur" : NumberInt(990)
        }
    ], 
    "lang" : "", 
    "langs" : null, 
    "hitlist" : NumberInt(0), 
    "country" : "", 
    "insertDate" : ISODate("2006-11-02T10:55:05.000+0000"), 
    "updateDate" : ISODate("2007-02-03T10:37:05.189+0000"), 
    "insert_date" : NumberInt(1431352882), 
    "update_date" : NumberInt(1435141711)
}

首先,没有工具可以根据java类生成,因为像“NumberInt”或“ISODate”这样的项目是未知的......我只是删除了这些术语并调整了我的javacode,但是无法查询我的mongodb并使用springframework ....将结果解析为java类。

如果我创建一个新类并将这个新类插入集合中,一切都很好...... 对此有何想法?

1 个答案:

答案 0 :(得分:0)

如果不需要,请尝试@Transient注释“隐藏”这些属性。见http://static.springsource.org/spring-data/data-document/docs/current/reference/html/#mapping-usage-annotations