如何将Java Map映射到PostgreSQL json数据类型?
请注意,我想将PostgreSQL-JSON-Data映射到Java Map,而不是String。因此,我不同意我的问题与Mapping postgreSQL JSON column to Hibernate value type重复。
实体示例:
<div id="loader_img">Loading</div>
<div class="content">
<img id="imgload" src="http://i.stack.imgur.com/rTQCa.jpg?s=512&g=1" />
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
(function() { // Avoid creating globals
// show loading image
$("#loader_img").show();
$("#imgload").hide();
// main image loaded ?
var img = $("#imgload");
if (img[0].complete) {
console.log("Complete");
imageDone();
} else {
console.log("Wait for load");
img.on('load', imageDone);
}
function imageDone() {
console.log("Loaded");
// hide/remove the loading image
$("#loader_img").fadeOut();
// And show the image!
img.show();
}
})();
</script>
用法:
@Entity
public class Test implements Serializable {
...
@Column(name = "DATA")
private Map<String, Object> data = new HashMap<>();
...
}
坚持时预期的json:
Test t = new Test();
t.getData().put("name", "James");
t.getData().put("number", 1);
t.getData().put("now", new Date());