Skip to content

Commit

Permalink
Updated doc.
Browse files Browse the repository at this point in the history
Moved failing tests to 'failing' package.
Added test for differing generic parameter types.
Pruned BaseTest and BaseMapTest.
Added comment about '-parameters' compiler option.
  • Loading branch information
eranl committed Nov 9, 2023
1 parent 102e00b commit cc269c5
Show file tree
Hide file tree
Showing 9 changed files with 345 additions and 972 deletions.
171 changes: 86 additions & 85 deletions android-record/pom.xml
Original file line number Diff line number Diff line change
@@ -1,96 +1,97 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<parent>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-modules-base</artifactId>
<version>2.16.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<parent>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-modules-base</artifactId>
<version>2.16.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>jackson-module-android-record</artifactId>
<name>Jackson module: Android Record Support</name>
<packaging>bundle</packaging>
<artifactId>jackson-module-android-record</artifactId>
<name>Jackson module: Android Record Support</name>
<packaging>bundle</packaging>

<description>Support deserialization into records on Android</description>
<url>https://github.com/FasterXML/jackson-modules-base</url>
<description>Support deserialization into records on Android</description>
<url>https://github.com/FasterXML/jackson-modules-base</url>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<properties>
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/module/androidrecord</packageVersion.dir>
<packageVersion.package>com.fasterxml.jackson.module.androidrecord</packageVersion.package>
</properties>
<properties>
<!-- Generate PackageVersion.java into this directory. -->
<packageVersion.dir>com/fasterxml/jackson/module/androidrecord</packageVersion.dir>
<packageVersion.package>com.fasterxml.jackson.module.androidrecord</packageVersion.package>
</properties>

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<fork>true</fork>
<useIncrementalCompilation>true</useIncrementalCompilation>
</configuration>
</plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<compilerArgs>
<!-- Module uses constructor parameter names (and types) to identify the canonical constructor -->
<arg>-parameters</arg>
</compilerArgs>
<fork>true</fork>
<useIncrementalCompilation>true</useIncrementalCompilation>
</configuration>
</plugin>

<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>process-packageVersion</id>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
<plugin>
<!-- Inherited from oss-base. Generate PackageVersion.java.-->
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<executions>
<execution>
<id>process-packageVersion</id>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>${version.plugin.animal-sniffer}</version>
<configuration>
<signature>
<groupId>com.toasttab.android</groupId>
<artifactId>gummy-bears-api-${version.android.sdk}</artifactId>
<version>${version.android.sdk.signature}</version>
</signature>
</configuration>
</plugin>
</plugins>
</build>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>${version.plugin.animal-sniffer}</version>
<configuration>
<signature>
<groupId>com.toasttab.android</groupId>
<artifactId>gummy-bears-api-${version.android.sdk}</artifactId>
<version>${version.android.sdk.signature}</version>
</signature>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@


/**
* Module that allows deserialization into records
* using the canonical constructor on Android,
* where java records are supported through desugaring,
* and Jackson's built-in support for records doesn't work,
* Module that allows (de)serialization of records using the canonical constructor and accessors on Android,
* where java records are supported through desugaring, and Jackson's built-in support for records doesn't work,
* since the desugared classes have a non-standard super class,
* and record component-related reflection methods are missing.
*
Expand All @@ -46,14 +44,17 @@
* Android Developers Blog article</a>
*
* <p>
* Note: this module is a no-op when no Android-desugared records are being deserialized,
* An attempt was made to make this module as consistent with Jackson's built-in support for records as possible,
* but gaps exist when using some of Jackson's advanced mapping features.
*
* <p>
* Note: this module is a no-op when no Android-desugared records are being (de)serialized,
* so it is safe to use in code shared between Android and non-Android platforms.
*
* <p>
* Note: the canonical record constructor is found
* through matching of parameter names and types with fields.
* Therefore, this module doesn't allow a deserialized desugared record class to have a custom
* constructor with the same set of parameter names and types as the canonical one.
* Note: the canonical record constructor is found through matching of parameter names and types with fields.
* Therefore, this module doesn't allow a deserialized desugared record to have a custom constructor
* with the same set of parameter names and types as the canonical one.
*
* @author Eran Leshem
**/
Expand All @@ -70,8 +71,6 @@ private AndroidRecordNaming(MapperConfig<?> config, AnnotatedClass forClass) {
super(config, forClass,
// no setters for (immutable) Records:
null,
// trickier: regular fields are ok (handled differently), but should
// we also allow getter discovery? For now let's do so
"get", "is", null);
_componentNames = getDesugaredRecordComponents(forClass.getRawType()).map(Field::getName)
.collect(Collectors.toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,26 @@ public boolean equals(Object o) {

private static final class MultipleConstructors extends RecordTag {
private final int i;
private final List<String> l;

private MultipleConstructors(int i) {
private MultipleConstructors(int i, List<String> l) {
this.i = i;
this.l = l;
}

private MultipleConstructors(String s) {
private MultipleConstructors(String s, List<String> l) {
i = Integer.parseInt(s);
this.l = l;
}

private MultipleConstructors(int i, String s, List<String> l) {
this.i = i;
this.l = l;
}

private MultipleConstructors(int i, String s) {
private MultipleConstructors(List<Integer> l, int i) {
this.i = i;
this.l = null;
}

int i() {
Expand Down Expand Up @@ -128,12 +136,15 @@ public void testSimple() throws JsonProcessingException {
}

public void testMultipleConstructors() throws JsonProcessingException {
assertEquals(9, _objectMapper.readValue(_objectMapper.writeValueAsString(new MultipleConstructors(9)),
List<String> l = Arrays.asList("bar", "baz");
assertEquals(9, _objectMapper.readValue(_objectMapper.writeValueAsString(new MultipleConstructors(9, l)),
MultipleConstructors.class).i());
assertEquals(9, _objectMapper.readValue(_objectMapper.writeValueAsString(
new MultipleConstructors("9")), MultipleConstructors.class).i());
new MultipleConstructors("9", l)), MultipleConstructors.class).i());
assertEquals(9, _objectMapper.readValue(_objectMapper.writeValueAsString(
new MultipleConstructors(9,"foobar", l)), MultipleConstructors.class).i());
assertEquals(9, _objectMapper.readValue(_objectMapper.writeValueAsString(
new MultipleConstructors(9,"foobar")), MultipleConstructors.class).i());
new MultipleConstructors(Arrays.asList(1, 2), 9)), MultipleConstructors.class).i());
}

public void testConflictingConstructors() {
Expand Down
Loading

0 comments on commit cc269c5

Please sign in to comment.