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

Records support, Java 17 and jigsaw modules #325

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e598ce7
feat - migrated maven project to java 16 (#1)
mxyns Mar 2, 2022
fc8c4d8
Merge pull request #2 from noahra/issue/#1
mxyns Mar 2, 2022
fff39bd
test - failing test for unsupported Record (#3)
mxyns Mar 2, 2022
7fc8851
Merge pull request #4 from noahra/issue/#3
mxyns Mar 2, 2022
4766703
test - add serialization test (#7)
lnsandnkth Mar 2, 2022
0d893a4
Merge pull request #8 from noahra/issue/#7
lnsandnkth Mar 2, 2022
da40903
test - fix added assertion (#3)
lnsandnkth Mar 2, 2022
6927007
Merge pull request #10 from noahra/issue/#3
lnsandnkth Mar 2, 2022
077c4d5
feat - record support with canonical constructor (#5) (PR #13)
yuxin-miao Mar 4, 2022
149b796
feat - handle multiple record constructors by using canonical constru…
mxyns Mar 4, 2022
4b7c1f0
test - add tests for any wrap and stream (#15)
lnsandnkth Mar 4, 2022
ac59b48
Merge pull request #17 from noahra/issue/#15
lnsandnkth Mar 4, 2022
8dc32ff
test - example of use of another constructor for record decoding (#16)
mxyns Mar 6, 2022
f921396
clean - reemoved syso/sout (#19)
mxyns Mar 6, 2022
2d2ff04
clean - removed unsused imports (#19)
mxyns Mar 6, 2022
37a6755
test - add tests for getRecordCtor (#21)
Mar 6, 2022
dc3a7af
Modularized, Java17, dependency-updates.
Aug 13, 2022
e736444
trying source and target tags to try to fix jitpack.io compilation
Aug 13, 2022
bdbd720
java.lang.module.FindException: Module com.fasterxml.jackson.databind
Aug 13, 2022
6a90a5a
transitive module Javassist not found
Aug 13, 2022
1652d87
revert transitive and open for more tests
Aug 13, 2022
0451822
fixed module-info using "requires static" for optional and test-only
Aug 16, 2022
26eab37
opened module
Aug 16, 2022
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
15 changes: 15 additions & 0 deletions DependencyUpdateSearch_Rules.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" comparisonMethod="maven" xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
<ignoreVersions>
<!-- Ignore Alpha's, Beta's, release candidates and milestones -->
<ignoreVersion type="regex">(?i).*Alpha(?:-?\d+)?</ignoreVersion>
<ignoreVersion type="regex">(?i).*a(?:-?\d+)?</ignoreVersion>
<ignoreVersion type="regex">(?i).*Beta(?:-?\d+)?</ignoreVersion>
<ignoreVersion type="regex">(?i).*-B(?:-?\d+)?</ignoreVersion>
<ignoreVersion type="regex">(?i).*RC(?:-?\d+)?</ignoreVersion>
<ignoreVersion type="regex">(?i).*CR(?:-?\d+)?</ignoreVersion>
<ignoreVersion type="regex">(?i).*M(?:-?\d+)?</ignoreVersion>
</ignoreVersions>
<rules>
</rules>
</ruleset>
76 changes: 62 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -52,32 +52,38 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
<version>2.13.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
<version>2.13.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.3</version>
<version>2.9.1</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.20</version>
<version>1.35</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.20</version>
<version>1.35</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down Expand Up @@ -119,17 +125,18 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.10.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<release>17</release>
<source>17</source>
<target>17</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -142,15 +149,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<version>3.4.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
Expand All @@ -172,7 +179,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -194,8 +201,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<version>2.20</version> <!-- note: 2.20.1 to 2.22.2 crash during tests -->
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<parallel>methods</parallel>
<threadCount>1</threadCount>
<reuseForks>false</reuseForks>
Expand All @@ -209,6 +217,46 @@
</includes>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.11.0</version>
<configuration>
<rulesUri>file:///${project.basedir}/DependencyUpdateSearch_Rules.xml</rulesUri>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>[3.3.2,)</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/jsoniter/ReflectionDecoderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public static Decoder create(ClassInfo classAndArgs) {
if (clazz.isEnum()) {
return new ReflectionEnumDecoder(clazz);
}
if (clazz.isRecord()) {
return new ReflectionRecordDecoder(classAndArgs).create();
}
return new ReflectionObjectDecoder(classAndArgs).create();
}
}
37 changes: 19 additions & 18 deletions src/main/java/com/jsoniter/ReflectionObjectDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

class ReflectionObjectDecoder {

private static Object NOT_SET = new Object() {
protected static Object NOT_SET = new Object() {
@Override
public String toString() {
return "NOT_SET";
}
};
private Map<Slice, Binding> allBindings = new HashMap<Slice, Binding>();
private String tempCacheKey;
private String ctorArgsCacheKey;
private int tempCount;
private long expectedTracker;
private int requiredIdx;
private int tempIdx;
private ClassDescriptor desc;
protected Map<Slice, Binding> allBindings = new HashMap<Slice, Binding>();
protected String tempCacheKey;
protected String ctorArgsCacheKey;
protected int tempCount;
protected long expectedTracker;
protected int requiredIdx;
protected int tempIdx;
protected ClassDescriptor desc;

public ReflectionObjectDecoder(ClassInfo classInfo) {
try {
Expand All @@ -34,7 +34,8 @@ public ReflectionObjectDecoder(ClassInfo classInfo) {
}
}

private final void init(ClassInfo classInfo) throws Exception {
protected final void init(ClassInfo classInfo) throws Exception {

Class clazz = classInfo.clazz;
ClassDescriptor desc = ClassDescriptor.getDecodingClassDescriptor(classInfo, true);
for (Binding param : desc.ctor.parameters) {
Expand Down Expand Up @@ -346,7 +347,7 @@ private void setToBinding(Object obj, Binding binding, Object value) throws Exce
}
}

private void setExtra(Object obj, Map<String, Object> extra) throws Exception {
protected void setExtra(Object obj, Map<String, Object> extra) throws Exception {
if (extra == null) {
return;
}
Expand All @@ -367,24 +368,24 @@ private void setExtra(Object obj, Map<String, Object> extra) throws Exception {
}
}

private boolean canNotSetDirectly(Binding binding) {
protected boolean canNotSetDirectly(Binding binding) {
return binding.field == null && binding.method == null;
}

private Object decodeBinding(JsonIterator iter, Binding binding) throws Exception {
protected Object decodeBinding(JsonIterator iter, Binding binding) throws Exception {
Object value;
value = binding.decoder.decode(iter);
return value;
}

private Object decodeBinding(JsonIterator iter, Object obj, Binding binding) throws Exception {
protected Object decodeBinding(JsonIterator iter, Object obj, Binding binding) throws Exception {
if (binding.valueCanReuse) {
CodegenAccess.setExistingObject(iter, binding.field.get(obj));
}
return decodeBinding(iter, binding);
}

private Map<String, Object> onUnknownProperty(JsonIterator iter, Slice fieldName, Map<String, Object> extra) throws IOException {
protected Map<String, Object> onUnknownProperty(JsonIterator iter, Slice fieldName, Map<String, Object> extra) throws IOException {
boolean shouldReadValue = desc.asExtraForUnknownProperties || !desc.keyValueTypeWrappers.isEmpty();
if (shouldReadValue) {
Any value = iter.readAny();
Expand All @@ -398,7 +399,7 @@ private Map<String, Object> onUnknownProperty(JsonIterator iter, Slice fieldName
return extra;
}

private List<String> collectMissingFields(long tracker) {
protected List<String> collectMissingFields(long tracker) {
List<String> missingFields = new ArrayList<String>();
for (Binding binding : allBindings.values()) {
if (binding.asMissingWhenNotPresent) {
Expand All @@ -409,7 +410,7 @@ private List<String> collectMissingFields(long tracker) {
return missingFields;
}

private void applyWrappers(Object[] temp, Object obj) throws Exception {
protected void applyWrappers(Object[] temp, Object obj) throws Exception {
for (WrapperDescriptor wrapper : desc.bindingTypeWrappers) {
Object[] args = new Object[wrapper.parameters.size()];
for (int i = 0; i < wrapper.parameters.size(); i++) {
Expand All @@ -422,7 +423,7 @@ private void applyWrappers(Object[] temp, Object obj) throws Exception {
}
}

private Object createNewObject(JsonIterator iter, Object[] temp) throws Exception {
protected Object createNewObject(JsonIterator iter, Object[] temp) throws Exception {
if (iter.tempObjects == null) {
iter.tempObjects = new HashMap<String, Object>();
}
Expand Down
Loading