1
1
package org .oser .tools .jdbc .experiment ;
2
2
3
+ import com .fasterxml .jackson .core .JsonProcessingException ;
4
+ import com .fasterxml .jackson .databind .DeserializationFeature ;
5
+ import com .fasterxml .jackson .databind .ObjectMapper ;
6
+ import com .fasterxml .jackson .databind .PropertyNamingStrategies ;
3
7
import com .github .benmanes .caffeine .cache .Cache ;
8
+ import org .junit .jupiter .api .Assertions ;
4
9
import org .junit .jupiter .api .Test ;
5
10
import org .oser .tools .jdbc .DbExporter ;
6
11
import org .oser .tools .jdbc .DbRecord ;
7
12
import org .oser .tools .jdbc .Fk ;
8
13
import org .oser .tools .jdbc .TestHelpers ;
14
+ import org .oser .tools .jdbc .experiment .testbed .Book ;
9
15
10
16
import java .io .IOException ;
11
17
import java .sql .Connection ;
@@ -25,8 +31,8 @@ void basicRequest() throws SQLException, IOException, ClassNotFoundException {
25
31
DbRecord book = dbExporter .contentAsTree (connection , "book" , 3 );
26
32
27
33
Cache <String , List <Fk >> filteredFkCache = dbExporter .getFilteredFkCache ();
28
- String sqlStatement = SelectAggregateAsJson .selectStatementForAggregateSelection ("book" , filteredFkCache , "oracle" );
29
- // String sqlStatement = SelectAggregateAsJson.selectStatementForAggregateSelection("book", filteredFkCache, "postgres");
34
+ // String sqlStatement = SelectAggregateAsJson.selectStatementForAggregateSelection("book", filteredFkCache, "oracle");
35
+ String sqlStatement = SelectAggregateAsJson .selectStatementForAggregateSelection ("book" , filteredFkCache , "postgres" );
30
36
31
37
System .out .println (sqlStatement );
32
38
@@ -71,4 +77,21 @@ void basicRequestOracle() throws SQLException, IOException, ClassNotFoundExcepti
71
77
invokeDbAndPrintJson (connection , sqlStatement );
72
78
}
73
79
80
+ // can we map hierarchies easily? Y
81
+ // does it work with arrays in json and single values in Java? Y
82
+ // can we easily convert underscore_separated to camelCase names? Y
83
+ @ Test
84
+ void deserializeJsonHierarchyToJava () throws JsonProcessingException {
85
+ String s = "{\" id\" : 3, \" title\" : \" Slaughter House Five\" , \" dms_id\" : 2, \" author_id\" : 3, \" number_pages\" : 350, \" images\" : [{\" id\" :33, \" name\" : \" authorPhoto\" }], \" author\" : [{\" id\" : 3, \" last_name\" : \" Vonnegut\" }]}" ;
86
+
87
+ ObjectMapper mapper = new ObjectMapper ();
88
+ mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
89
+ mapper .configure (DeserializationFeature .ACCEPT_SINGLE_VALUE_AS_ARRAY , true );
90
+ mapper .configure (DeserializationFeature .UNWRAP_SINGLE_VALUE_ARRAYS , true );
91
+ mapper .setPropertyNamingStrategy (PropertyNamingStrategies .SNAKE_CASE );
92
+ Book bookFromJSON = mapper .readValue (s , Book .class );
93
+
94
+ Assertions .assertNotNull (bookFromJSON );
95
+ System .out .println (bookFromJSON );
96
+ }
74
97
}
0 commit comments