manifold-systems / manifold

Manifold is a Java compiler plugin, its features include Metaprogramming, Properties, Extension Methods, Operator Overloading, Templates, a Preprocessor, and more.
http://manifold.systems/
Apache License 2.0
2.43k stars 125 forks source link

Can't use lowerCamelCase attributes for an nested object in JSON. #449

Closed devdufutur closed 1 year ago

devdufutur commented 1 year ago

Describe the bug The use of lowerCamelCase attribute for a nested object in JSON leads to an error.

To Reproduce Steps to reproduce the behavior: 1.Create a Person.json with the following content : { "name": "John Doe", "age": 39, "address": { "number": 9604, "street": "Donald Court", "city": "Golden Shores", "state": "FL" } } 2.Instanciate Person object like that : var person = Person.builder() .withName("Someone") .build(); System.out.println(person.write().toJson());

Expected behavior It should compile, run and print something like : { "name": "Someone" }

Screenshots image

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

Stack trace [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ testmanifold4 --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 3 source files to C:\Users\Rudy\IdeaProjects\testmanifold4\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /org/example/model/Person.java:[113,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[113,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[116,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[116,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[120,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[120,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[123,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[123,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[127,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[127,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[130,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[130,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[134,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[134,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[137,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[137,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[148,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[148,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[151,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[151,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[154,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[154,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[157,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[157,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[113,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[116,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[120,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[123,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[127,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[130,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[134,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[137,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[148,45] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[151,45] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[154,45] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[157,45] Cannot access write-only property 'address' [INFO] 36 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 6.892 s [INFO] Finished at: 2023-05-08T20:42:17+02:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project testmanifold4: Compilation failure: Compilation failure: [ERROR] /org/example/model/Person.java:[113,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[113,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[116,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[116,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[120,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[120,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[123,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[123,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[127,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[127,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[130,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[130,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[134,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[134,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[137,43] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[137,50] element value must be a constant expression [ERROR] /org/example/model/Person.java:[148,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[148,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[151,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[151,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[154,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[154,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[157,45] non-static variable address cannot be referenced from a static context [ERROR] /org/example/model/Person.java:[157,52] element value must be a constant expression [ERROR] /org/example/model/Person.java:[113,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[116,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[120,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[123,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[127,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[130,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[134,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[137,43] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[148,45] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[151,45] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[154,45] Cannot access write-only property 'address' [ERROR] /org/example/model/Person.java:[157,45] Cannot access write-only property 'address' [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Process finished with exit code 1

rsmckinney commented 1 year ago

@devdufutur This works fine for me. Can you provide more details about your build configuration? The pom.xml or build.gradle may help diagnose what is wrong. Thanks.

devdufutur commented 1 year ago

Sure ! ` <?xml version="1.0" encoding="UTF-8"?> <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">

4.0.0
<groupId>org.example</groupId>
<artifactId>testmanifold4</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <manifold.version>2023.1.5</manifold.version>
</properties>

<dependencies>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-delegation-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-props-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-graphql-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-xml-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-yaml-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-csv-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-js-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-collections</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-science</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-templates-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>systems.manifold</groupId>
        <artifactId>manifold-tuple-rt</artifactId>
        <version>${manifold.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>

            <version>3.8.0</version>

            <configuration>
                <encoding>UTF-8</encoding>
                <compilerArgs>
                    <arg>-Xplugin:Manifold</arg>
                </compilerArgs>

                <annotationProcessorPaths>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-delegation</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-props</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-graphql</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-xml</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-yaml</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-csv</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-exceptions</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-image</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-properties</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-js</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-preprocessor</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-strings</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-templates</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                    <path>
                        <groupId>systems.manifold</groupId>
                        <artifactId>manifold-tuple</artifactId>
                        <version>${manifold.version}</version>
                    </path>
                </annotationProcessorPaths>

            </configuration>
        </plugin>
    </plugins>
</build>

`

I even tried by adding this kind of JSON in a clone of manifold-sample-project, I had the same result :/

devdufutur commented 1 year ago

https://gist.github.com/devdufutur/dffcf0af2e3b5635355ee32a603c2535

rsmckinney commented 1 year ago

There appears to be a conflict between manifold-props and manifold-json. For now, you can remove or comment out dependencies/paths for manifold-props and manifold-props-rt when working with manifold-json. I should have a fix for this issue in the next release, end of this week. Thanks for reporting this!

rsmckinney commented 1 year ago

Fix available with release 2023.1.8, IntelliJ plugin update published. Note, IntelliJ plugin update is usually available within 24 hours of publishing.

Thanks for filing this issue!

devdufutur commented 1 year ago

Sorry, forgot to reply ! It worked great without manifold-props as a fix. Thanks @rsmckinney.