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

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

Closed
devdufutur opened this issue May 8, 2023 · 6 comments
Closed

Comments

@devdufutur
Copy link

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):

  • OS Type & Version: Windows 10
  • Java/JDK version: JDK 17 temurin
  • IDE version (IntelliJ IDEA or Android Studio): IDEA 2023.1.1
  • Manifold version:2023.1.5
  • Manifold IntelliJ plugin version: 2023.1.2

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
Copy link
Member

@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
Copy link
Author

devdufutur commented May 9, 2023

Sure !
`


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
Copy link
Author

@rsmckinney
Copy link
Member

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 added a commit that referenced this issue May 11, 2023
- json type manifold code gen, maintain a single file field at the top-level and reference that with fully qualified name, avoids naming collision with manifold-props
rsmckinney added a commit that referenced this issue May 16, 2023
- handle shadowing where an instance field shadows an inner class of the same name. This is particularly useful in code gen where both a property and an inner type are derived from the same element. Otherwise, use-cases such as: Person.address.builder(), don't work because address resolves as the field and not the inner class.
- json type manifold code gen, maintain a single file field at the top-level and reference that with fully qualified name, avoids naming collision with manifold-props
rsmckinney added a commit to manifold-systems/manifold-ij that referenced this issue May 16, 2023
- handle shadowing where an instance field shadows an inner class of the same name. This is particularly useful in code gen where both a property and an inner type are derived from the same element. Otherwise, use-cases such as: Person.address.builder(), don't work because address resolves as the field and not the inner class.
@rsmckinney
Copy link
Member

rsmckinney commented May 16, 2023

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants