You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by st...@apache.org on 2026/07/29 07:20:27 UTC
(tomee) branch main updated: add a test for using @JsonbVisibility on java Records
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git
The following commit(s) were added to refs/heads/main by this push:
new ff3ce4597e add a test for using @JsonbVisibility on java Records
ff3ce4597e is described below
commit ff3ce4597e523a4d3d10fa8478d0b2588a8ebf7f
Author: Mark Struberg <st...@apache.org>
AuthorDate: Wed Jul 29 09:19:47 2026 +0200
add a test for using @JsonbVisibility on java Records
---
.../rest/JsonbRecordMethodVisibilityTest.java | 62 ++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/examples/jsonb-custom-serializer/src/test/java/org/superbiz/rest/JsonbRecordMethodVisibilityTest.java b/examples/jsonb-custom-serializer/src/test/java/org/superbiz/rest/JsonbRecordMethodVisibilityTest.java
new file mode 100644
index 0000000000..4a24065892
--- /dev/null
+++ b/examples/jsonb-custom-serializer/src/test/java/org/superbiz/rest/JsonbRecordMethodVisibilityTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.rest;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.junit.Test;
+
+import jakarta.json.bind.Jsonb;
+import jakarta.json.bind.annotation.JsonbVisibility;
+import jakarta.json.bind.config.PropertyVisibilityStrategy;
+import jakarta.json.bind.spi.JsonbProvider;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test JsonbVisibility for JsonB handling of records
+ */
+public class JsonbRecordMethodVisibilityTest {
+
+ @Test
+ public void testToJson() {
+ Jsonb jsonb = JsonbProvider.provider().create().build();
+
+ final String json = jsonb.toJson(new Person(45, "Clara"));
+ assertEquals("{\"age\":45,\"name\":\"Clara\"}", json);
+ }
+
+ @JsonbVisibility(RecordVisibilityStrategy.class)
+ public static record Person(int age, String name) {
+
+ public String personInfo() {
+ return name + "/" + age;
+ }
+ }
+
+ public static class RecordVisibilityStrategy implements PropertyVisibilityStrategy {
+ @Override
+ public boolean isVisible(Field field) {
+ return true;
+ }
+
+ @Override
+ public boolean isVisible(Method method) {
+ return !"personInfo".equals(method.getName());
+ }
+ }
+}