Serialization of business objects as JSON

I am trying to serialize my business objects to JSON for use by a Javascript application. The problem is that I'm trying to keep my business objects “clean” in the sense that they are not aware of data access or persistence. It seems to me that "diluting" my objects with the toJSON () function will be contrary to this goal. On the other hand, using an external object to serialize my business objects will not work, as I keep all my instance variables private.

Am I approaching this completely wrong?

+3
source share
3 answers

, , JavaScript. , , . , , , - getter.

+6

JSON? ? , , getter.

JavaScript, , , , , , .

, Java . getter. ( ) , , - .

. toString. ( toJson.)

+1

JSON , javascript (, Java)? : JSON Javascript , , Java. javascript-, .

If it is in Java, there are libraries that can help; for example ( Jackson ) can deserialize any bean using regular introspection of the getX / setX method; plus additional (and optional) annotations.

0
source

Source: https://habr.com/ru/post/1705838/


All Articles