How to save json object in hibernation base field

my case is as follows. I have a JSF form with three output texts, and the corresponding input texts allow:

outputtext1 - inputtext1

outputtext2 - inputtext2

outputtext3 - inputtext3

I am currently using the backba Save method to save them to the database (the hibernate object allows us to use table1 with the primary key table1.id) in the fields table1.field1, table1.field2, table1.field3.

Thus, each record in the table has values ​​inserted into the input texts.

My question is how can I save form data in a database in a form like this:

{"outputtext1: inputtext1", "outputtext2: inputtext2". "outputtext3: inputtext3"}

and then pick them up again, analyze and rebuild the form. I mean manipulating form data as a JSON object ... But I'm new to Java + JSON, so some guidelines would be really helpful for me!

This is an example, a form is dynamic and is created on the fly.

+5
source share
4 answers

Why do you want to serialize / deserialize JSON to send it directly to the database? Deserialization has its problems, and multiple deserializations can (will not) be a source of problems.

You must save the fields as attributes from this object, and then use libraries such as Gson to generate JSON from the object.


Refresh

, .

Map<String,String>, , , FieldRecord , -.

, JSON , . JSONs, , . , .

+4

, BLOB json, java, json recomend https://code.google.com/p/json-simple/

+2

JSONObject String, . , JSONObject, :

       JSONObject obj = new JSONObject(stringRepresentationOfJSON);
+1

change the hibernate mapping as follows: JSONObject obj = new JSONObject (stringRepresentationOfJSON);

-2
source

All Articles