Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping over groovy metadata class + groovy test. #118

Merged
merged 9 commits into from
Feb 21, 2024
21 changes: 21 additions & 0 deletions jr-objects/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ has no other dependencies, and provides additional builder-style content generat
<artifactId>jackson-core</artifactId>
<version>${jackson.version.core}</version>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>4.0.18</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -54,6 +60,21 @@ has no other dependencies, and provides additional builder-style content generat
</configuration>

</plugin>

<!-- 20-Feb-2024, tatu: Need Groovy compilation for one test
-->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ private static void _introspect(Class<?> currType, Map<String, PropBuilder> prop
final int flags = m.getModifiers();
// 13-Jun-2015, tatu: Skip synthetic, bridge methods altogether, for now
// at least (add more complex handling only if absolutely necessary)
if (Modifier.isStatic(flags)
|| m.isSynthetic() || m.isBridge()) {
if (Modifier.isStatic(flags) || m.isSynthetic() || m.isBridge() || isGroovyMetaClass(m.getReturnType())) {
continue;
}
Class<?> argTypes[] = m.getParameterTypes();
Expand Down Expand Up @@ -158,12 +157,7 @@ private static void _introspect(Class<?> currType, Map<String, PropBuilder> prop
}

private static PropBuilder _propFrom(Map<String,PropBuilder> 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) {
Expand All @@ -182,4 +176,13 @@ private static String decap(String name) {
return name;
}

/**
* Helper method to detect Groovy's problematic metadata accessor type.
*
* @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 "groovy.lang.MetaClass".equals(clazz.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.fasterxml.jackson.jr

import org.junit.Test
import org.junit.Assert

import com.fasterxml.jackson.jr.ob.JSON
import com.fasterxml.jackson.jr.ob.TestBase

class GroovyTest
{
@Test
void testSimpleGroovyObject() throws Exception {
def json = JSON.std.asString(new GroovyOb())
def expected = """{"AAAAA_A_Field_Starting_With_Two_Capital_Letters":"XYZ","aDouble":0.0,"aPublicInitializedInteger":56,"aPublicInitializedIntegerObject":1516,"aPublicUninitializedInteger":0,"anInitializedIntegerObject":1112,"anInitializedPublicString":"stringData","anInitializedString":"ABC","anInteger":0,"anIntegerWithValue":12}"""
Assert.assertEquals(json, expected)
}
}

class GroovyOb {
int anInteger
int anIntegerWithValue = 12

static int anStaticInteger = 34
static int anStaticIntegerWithValue = 34

public int aPublicUninitializedInteger
public int aPublicInitializedInteger = 56

private int aPrivateUninitializedInteger
private int aPrivateInitializedInteger = 78

public static int aPublicStaticUninitializedInteger
public static int aPublicStaticInitializedInteger = 910

Integer anIntegerObject
Integer anInitializedIntegerObject = 1112

static Integer aStaticIntegerObject
static Integer aStaticInitializedIntegerObject = 1314

public Integer aPublicUninitializedIntegerObject
public Integer aPublicInitializedIntegerObject = 1516

public static Integer aPublicStaticUninitializedIntegerObject
public static Integer aPublicStaticInitializedIntegerObject = 1718

String aString
String anInitializedString = "ABC"

static String aStaticString = "jacksonJR"

public String aPublicString
public String anInitializedPublicString = "stringData"

public String AAAAA_A_Field_Starting_With_Two_Capital_Letters = "XYZ"
//Other Items
public static String staticStr = "jacksonJR" // Public Static Object
static int anStaticInt // Uninitialized Static Object
public double aDouble // uninitialized primitive
public Double aDoubleObject // testing boxing object
private int hiddenvalue = 123 // private value
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,16 @@ public boolean isClosed() {
*/

@Override
public String getCurrentName() {
public String currentName() {
return (_nodeCursor == null) ? null : _nodeCursor.getCurrentName();
}

@Override
@Deprecated // since 2.17
public String getCurrentName() {
return currentName();
}

@Override
public void overrideCurrentName(String name)
{
Expand All @@ -211,13 +217,25 @@ public JsonStreamContext getParsingContext() {
}

@Override
public JsonLocation currentTokenLocation() {
return JsonLocation.NA;
}

@Override
@Deprecated // since 2.17
public JsonLocation getTokenLocation() {
return currentTokenLocation();
}

@Override
public JsonLocation currentLocation() {
return JsonLocation.NA;
}

@Override
@Deprecated // since 2.17
public JsonLocation getCurrentLocation() {
return JsonLocation.NA;
return currentLocation();
}

/*
Expand Down
11 changes: 10 additions & 1 deletion release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Jonas Konrad (@yawkat)
* Suggested #88: Make `jr-stree` dependency to `jr-objects` optional
(2.13.0)

Nikolay Chashnikov (@chashnikov)

* Requested #93: Skip serialization of `groovy.lang.MetaClass`
values to avoid `StackOverflowError`
(2.17.0)

Gerben Oolbekkink (@github)

* Reported #98: `module-info.java` of `jr-stree` refers to module `com.fasterxml.jackson.jr.ob.api`,
Expand All @@ -42,5 +48,8 @@ Julian Honnen (@jhonnen)

@Shounaks

* Contributed implf ro #100: Add support for `java.time` (Java 8 date/time) types
* Contributed fix for #93: Skip serialization of `groovy.lang.MetaClass` values
to avoid `StackOverflowError`
(2.17.0)
* Contributed impl for #100: Add support for `java.time` (Java 8 date/time) types
(2.17.0)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Modules:

#78: Deserializes "null" to "0.0" for `java.lang.Double` (wrapper)
(reported by @bill-phast)
#93: Skip serialization of `groovy.lang.MetaClass` values to avoid `StackOverflowError`
(requested by Nikolay C)
(fix contributed by @Shounaks)
#100: Add support for `java.time` (Java 8 date/time) types
(requested by @sebastian-zero)
(contributed by @Shounaks)
Expand Down