Skip to content

Commit 2c65147

Browse files
committed
fixes field property
1 parent 81e9d68 commit 2c65147

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

diana-driver-commons/src/main/java/org/jnosql/diana/driver/DefaultJsonbSupplier.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,39 @@
1616

1717
import javax.json.bind.Jsonb;
1818
import 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

2024
enum 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
}

diana-driver-commons/src/test/java/org/jnosql/diana/driver/DefaultJsonBSupplierTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
package org.jnosql.diana.driver;
1616

17-
import org.junit.jupiter.api.Assertions;
1817
import org.junit.jupiter.api.Test;
1918

2019
import 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
}

diana-driver-commons/src/test/java/org/jnosql/diana/driver/User.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)