5

を持っています@Entity

@Entity
@Table(name = "variable")
@XmlRootElement
public class Variable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(unique = true, nullable = false)
    private String name;

    @Column
    @Enumerated(EnumType.STRING)
    private VariableType type;

    @Column(nullable = false)
    private String units;

    @Column
    private String description;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_on", nullable = false)
    private Date createdOn;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "retired_on", nullable = true)
    private Date retiredOn;

    @Column(nullable = false)
    private boolean core;
}

を使用してデータを挿入するVariableManagerと、データベース内に正しく挿入されます

variableCrudService.create(new Variable(name, type, units, description, new Date(), core));

ログで確認できます

 added variable id=13 name=v4 type=String units=u4 description=created with web service createdOn=2013-01-14 14:43:57.0 retiredOn=null core=true

そしてデータベースmysql> select * from variable;

+----+------+------------+-------+--------------------------+---------------------+------------+------+
| id | name | type       | units | description              | created_on          | retired_on | core |
+----+------+------------+-------+--------------------------+---------------------+------------+------+
|  1 | v1   | Double     | u1    | created via migration    | 2013-01-14 13:15:19 | NULL       |    1 |
|  2 | v2   | String     | u2    | created via migration    | 2013-01-14 13:15:19 | NULL       |    1 |
|  3 | v3   | BigDecimal | u3    | created via migration    | 2013-01-14 13:15:19 | NULL       |    0 |
| 12 | v4   | String     | u4    | created with web service | 2013-01-14 14:41:31 | NULL       |    1 |
+----+------+------------+-------+--------------------------+---------------------+------------+------+
4 rows in set (0.00 sec)  

しかし、カールを使用してこれをテストすると、タイムスタンプが奇妙な形式で表示されます

[
    {
        "core": true, 
        "createdOn": 1358198119000, 
        "description": "created via migration", 
        "id": 1, 
        "name": "v1", 
        "retiredOn": null, 
        "type": "Double", 
        "units": "u1"
    }, 
    {
        "core": true, 
        "createdOn": 1358198119000, 
        "description": "created via migration", 
        "id": 2, 
        "name": "v2", 
        "retiredOn": null, 
        "type": "String", 
        "units": "u2"
    }, 
    {
        "core": false, 
        "createdOn": 1358198119000, 
        "description": "created via migration", 
        "id": 3, 
        "name": "v3", 
        "retiredOn": null, 
        "type": "BigDecimal", 
        "units": "u3"
    }, 
    {
        "core": true, 
        "createdOn": 1358203437000, 
        "description": "created with web service", 
        "id": 13, 
        "name": "v4", 
        "retiredOn": null, 
        "type": "String", 
        "units": "u4"
    }
]

ここで何が起こっているのですか?ここで私が間違っていることは何ですか?

4

1 に答える 1

0

日付の値は正しいと思いますが、おそらく希望する形式ではありません。カスタムの日付アダプターを作成して、JAXB が値を適切な形式で非整列化できるようにすることができます。これを見てください: jaxb unmarshal タイムスタンプ

于 2013-01-15T14:01:39.223 に答える