diff --git a/jr-objects/pom.xml b/jr-objects/pom.xml
index 08625dc8..c69235cd 100644
--- a/jr-objects/pom.xml
+++ b/jr-objects/pom.xml
@@ -40,6 +40,12 @@ has no other dependencies, and provides additional builder-style content generat
jackson-core
${jackson.version.core}
+
+ org.codehaus.groovy
+ groovy
+ 3.0.18
+ test
+
@@ -64,9 +70,6 @@ has no other dependencies, and provides additional builder-style content generat
replace
generate-sources
-
diff --git a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java
index 1eb5815f..b5e602cb 100644
--- a/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java
+++ b/jr-objects/src/main/java/com/fasterxml/jackson/jr/ob/impl/BeanPropertyIntrospector.java
@@ -88,7 +88,7 @@ private POJODefinition _construct(Class> beanType, int features)
private static void _introspect(Class> currType, Map props,
int features)
{
- if (currType == null || currType == Object.class) {
+ if (currType == null || currType == Object.class || isGroovyMetaClass(currType)) {
return;
}
// First, check base type
@@ -158,12 +158,7 @@ private static void _introspect(Class> currType, Map prop
}
private static PropBuilder _propFrom(Map props, String name) {
- PropBuilder prop = props.get(name);
- if (prop == null) {
- prop = Prop.builder(name);
- props.put(name, prop);
- }
- return prop;
+ return props.computeIfAbsent(name, Prop::builder);
}
private static String decap(String name) {
@@ -182,4 +177,13 @@ private static String decap(String name) {
return name;
}
+ /**
+ * Another helper method to deal with Groovy's problematic metadata accessors
+ *
+ * @implNote Groovy MetaClass have cyclic reference, and hence the class containing it should not be serialised without
+ * either removing that reference, or skipping over such references.
+ */
+ protected static boolean isGroovyMetaClass(Class> clazz) {
+ return clazz.getName().startsWith("groovy.lang");
+ }
}
diff --git a/jr-objects/src/test/java/com/fasterxml/jackson/jr/GroovyTest.groovy b/jr-objects/src/test/java/com/fasterxml/jackson/jr/GroovyTest.groovy
new file mode 100644
index 00000000..16e2e63e
--- /dev/null
+++ b/jr-objects/src/test/java/com/fasterxml/jackson/jr/GroovyTest.groovy
@@ -0,0 +1,21 @@
+package com.fasterxml.jackson.jr
+
+import com.fasterxml.jackson.jr.ob.JSON
+import com.fasterxml.jackson.jr.ob.TestBase
+
+class GroovyTest extends TestBase {
+
+ void testSimpleObject() throws Exception {
+ var data = JSON.std.asString(new MyClass())
+ var expected = "{\"aDouble\":0.0,\"aStr\":\"stringData\",\"anInt\":0,\"metaClass\":{}}";
+ assertEquals(data, expected)
+ }
+
+ private class MyClass {
+ public int anInt; //testing groovy primitive
+ public String aStr = "stringData"; //testing allocated object
+
+ public double aDouble; //
+ public Double aDoublesd; //testing boxing object
+ }
+}