File tree Expand file tree Collapse file tree 3 files changed +29
-10
lines changed
main/java/org/jnosql/diana/driver
test/java/org/jnosql/diana/driver Expand file tree Collapse file tree 3 files changed +29
-10
lines changed Original file line number Diff line number Diff line change 1616
1717import javax .json .bind .Jsonb ;
1818import javax .json .bind .JsonbBuilder ;
19+ import javax .json .bind .JsonbConfig ;
20+ import javax .json .bind .config .PropertyVisibilityStrategy ;
21+ import java .lang .reflect .Field ;
22+ import java .lang .reflect .Method ;
1923
2024enum DefaultJsonbSupplier implements JsonbSupplier {
2125
2226 INSTANCE ;
2327
24- private Jsonb json = JsonbBuilder .create ();
28+ {
29+ JsonbConfig config = new JsonbConfig ().withPropertyVisibilityStrategy (new PrivateVisibilityStrategy ());
30+ this .json = JsonbBuilder .newBuilder ().withConfig (config ).build ();
31+ }
32+
33+ private final Jsonb json ;
2534
2635 @ Override
2736 public Jsonb get () {
2837 return json ;
2938 }
39+
40+
41+ class PrivateVisibilityStrategy implements PropertyVisibilityStrategy {
42+
43+ @ Override
44+ public boolean isVisible (Field field ) {
45+ return true ;
46+ }
47+
48+ @ Override
49+ public boolean isVisible (Method method ) {
50+ return false ;
51+ }
52+
53+ }
3054}
Original file line number Diff line number Diff line change 1414 */
1515package org .jnosql .diana .driver ;
1616
17- import org .junit .jupiter .api .Assertions ;
1817import org .junit .jupiter .api .Test ;
1918
2019import javax .json .bind .Jsonb ;
@@ -42,6 +41,6 @@ public void shouldReadFromField() {
4241 User user = new User ("Ada" , 32 );
4342 String json = jsonb .toJson (user );
4443 assertNotNull (json );
45- assertEquals (user , jsonb .toJson (json ));
44+ assertEquals (user , jsonb .fromJson (json , User . class ));
4645 }
4746}
Original file line number Diff line number Diff line change @@ -22,18 +22,14 @@ public class User {
2222
2323 private Integer age ;
2424
25+ public User () {
26+ }
27+
2528 public User (String name , Integer age ) {
2629 this .name = name ;
2730 this .age = age ;
2831 }
2932
30- public String getName () {
31- return name ;
32- }
33-
34- public Integer getAge () {
35- return age ;
36- }
3733
3834 @ Override
3935 public boolean equals (Object o ) {
You can’t perform that action at this time.
0 commit comments