File tree 2 files changed +17
-3
lines changed
common/src/main/java/by/andd3dfx/mapper
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 21
21
- Encryption [ example] ( common/src/main/java/by/andd3dfx/encrypt )
22
22
- Guice usage [ example] ( common/src/main/java/by/andd3dfx/guice )
23
23
- [ JMS connector] ( common/src/main/java/by/andd3dfx/jms ) to get queue size by JMX
24
- - MapStruct mapper [ example] ( common/src/main/java/by/andd3dfx/mapper )
24
+ - ObjectMapper usage [ example] ( common/src/main/java/by/andd3dfx/mapper ) with serialization/deserialization object to/from string
25
25
- [ Example] ( common/src/main/java/by/andd3dfx/masking ) of annotation-driven masker
26
26
- [ Example] ( common/src/main/java/by/andd3dfx/sockets ) of work with sockets
27
27
- [ Example] ( common/src/main/java/by/andd3dfx/testing ) of testing classes using Mockito / JMock mocks
Original file line number Diff line number Diff line change @@ -7,13 +7,27 @@ public class MapperUtil {
7
7
8
8
private static ObjectMapper objectMapper = new ObjectMapper ();
9
9
10
+ /**
11
+ * Deserialize object from JSON string
12
+ *
13
+ * @param jsonString JSON string
14
+ * @param aClass object class
15
+ * @param <T> type of object class
16
+ * @return deserialized object of class type T
17
+ */
10
18
@ SneakyThrows
11
19
public static <T > T jsonToObject (String jsonString , Class <T > aClass ) {
12
20
return objectMapper .readValue (jsonString , aClass );
13
21
}
14
22
23
+ /**
24
+ * Serialize object to string
25
+ *
26
+ * @param object object for serialization
27
+ * @return string with serialized object
28
+ */
15
29
@ SneakyThrows
16
- public static String toJson (Object msa ) {
17
- return objectMapper .writeValueAsString (msa );
30
+ public static String toJson (Object object ) {
31
+ return objectMapper .writeValueAsString (object );
18
32
}
19
33
}
You can’t perform that action at this time.
0 commit comments