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

Java 17 Compatibility #176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions genson-scala/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<description>Genson extension for Scala language</description>

<properties>
<scala.version>2.11</scala.version>
<scala.range.version>2.11.11</scala.range.version>
<scala.version>2.12</scala.version>
<scala.range.version>2.12.15</scala.range.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>5.0.3</version>
<version>9.2</version>
<scope>test</scope>
</dependency>

Expand Down
11 changes: 9 additions & 2 deletions genson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
<version>5.0.3</version>
<version>9.2</version>
<optional>true</optional>
</dependency>

Expand All @@ -40,6 +40,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
Expand Down Expand Up @@ -129,7 +136,7 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.8.v20121106</version>
<version>9.4.17.v20190418</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private class ClassConstructorsVisitor extends ClassVisitor {
public ClassConstructorsVisitor(Class<?> forClass,
Map<Constructor<?>, String[]> ctrParameterNames,
Map<Method, String[]> methodParameterNames) {
super(Opcodes.ASM5);
super(Opcodes.ASM7);
this.forClass = forClass;
this.ctrParameterNames = ctrParameterNames;
this.methodParameterNames = methodParameterNames;
Expand Down Expand Up @@ -161,7 +161,7 @@ private abstract class BaseMethodVisitor extends MethodVisitor {

public BaseMethodVisitor(Class<?> forClass, boolean ztatic, String desc,
Map<Method, String[]> parameterNamesMap) {
super(Opcodes.ASM5);
super(Opcodes.ASM7);
this.forClass = forClass;
this.ztatic = ztatic;
paramTypes = Type.getArgumentTypes(desc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ public VisibilityFilter(int... modifier) {
* @return true if this member is visible according to this filter.
*/
public final boolean isVisible(Member member) {
return isVisible(member.getModifiers());
Class<?> clazz = member.getDeclaringClass();
String className = clazz.getName();
if(className.startsWith("java.") || className.startsWith("javax.")){
return Modifier.isPublic(member.getModifiers());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not enough. The current impl of isVisible does apply a filter on things like transient, static, volatile, etc. You probably still want to leverage the same filter logic. It's worth adding some tests too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably reverse the steps. Run the existing visibility check first, then the additional check for java/javax class afterwards

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this sounds like a good option.

}
else{
return isVisible(member.getModifiers());
}
}

public final boolean isVisible(int modifiers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public void testDeserializeSerializeTweets() throws JsonParseException, JsonMapp

// we first deserialize the original data and ensure that genson deserialized it exactly as
// jackson
Tweet[] jacksonTweets = mapper.readValue(ClassLoader.class
.getResourceAsStream("/TWEETS.json"), Tweet[].class);
Tweet[] gensonTweets = genson.deserialize(new InputStreamReader(ClassLoader.class
.getResourceAsStream("/TWEETS.json")), Tweet[].class);
Tweet[] jacksonTweets = mapper.readValue(ClassLoader
.getSystemResourceAsStream("TWEETS.json"), Tweet[].class);
Tweet[] gensonTweets = genson.deserialize(new InputStreamReader(ClassLoader
.getSystemResourceAsStream("TWEETS.json")), Tweet[].class);
assertArrayEquals(jacksonTweets, gensonTweets);

// and then we serialize it and try to deserialize again and match again what was
Expand All @@ -170,10 +170,10 @@ public void testDeserializeSerializeReaderShort() throws IOException {
Genson genson = getGenson();

// same test as before...
Feed jacksonShortFeed = mapper.readValue(ClassLoader.class
.getResourceAsStream("/READER_SHORT.json"), Feed.class);
Feed gensonShortFeed = genson.deserialize(new InputStreamReader(ClassLoader.class
.getResourceAsStream("/READER_SHORT.json")), Feed.class);
Feed jacksonShortFeed = mapper.readValue(ClassLoader
.getSystemResourceAsStream("READER_SHORT.json"), Feed.class);
Feed gensonShortFeed = genson.deserialize(new InputStreamReader(ClassLoader
.getSystemResourceAsStream("READER_SHORT.json")), Feed.class);
assertEquals(jacksonShortFeed, gensonShortFeed);
String shortFeedString = genson.serialize(gensonShortFeed);
gensonShortFeed = genson.deserialize(shortFeedString, Feed.class);
Expand All @@ -187,10 +187,10 @@ public void testDeserializeSerializeReaderLong() throws IOException {
Genson genson = getGenson();

// and again for the long reader data...
Feed jacksonLongFeed = mapper.readValue(ClassLoader.class
.getResourceAsStream("/READER_LONG.json"), Feed.class);
Feed gensonLongFeed = genson.deserialize(new InputStreamReader(ClassLoader.class
.getResourceAsStream("/READER_LONG.json")), Feed.class);
Feed jacksonLongFeed = mapper.readValue(ClassLoader
.getSystemResourceAsStream("READER_LONG.json"), Feed.class);
Feed gensonLongFeed = genson.deserialize(new InputStreamReader(ClassLoader
.getSystemResourceAsStream("READER_LONG.json")), Feed.class);
assertEquals(jacksonLongFeed, gensonLongFeed);
String longFeedString = genson.serialize(gensonLongFeed);
gensonLongFeed = genson.deserialize(longFeedString, Feed.class);
Expand Down Expand Up @@ -241,10 +241,10 @@ public void testSerializeDeserializeMediaContent() throws JsonParseException,
JsonMappingException, IOException {
ObjectMapper mapper = new ObjectMapper();
Genson genson = new Genson();
MediaContent jacksonContent = mapper.readValue(ClassLoader.class
.getResourceAsStream("/MEDIA_CONTENT.json"), MediaContent.class);
MediaContent gensonContent = genson.deserialize(new InputStreamReader(ClassLoader.class
.getResourceAsStream("/MEDIA_CONTENT.json")), MediaContent.class);
MediaContent jacksonContent = mapper.readValue(ClassLoader
.getSystemResourceAsStream("MEDIA_CONTENT.json"), MediaContent.class);
MediaContent gensonContent = genson.deserialize(new InputStreamReader(ClassLoader
.getSystemResourceAsStream("MEDIA_CONTENT.json")), MediaContent.class);
assertEquals(jacksonContent, gensonContent);
String json = genson.serialize(gensonContent);
gensonContent = genson.deserialize(json, MediaContent.class);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<additionalOptions>-Xdoclint:none</additionalOptions>

<!-- Be clear about the required JDK build version. -->
<jdk.version>1.8</jdk.version>
<jdk.version>17</jdk.version>

</properties>

Expand Down