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
Support builder classes for immutable objects #22
Comments
Currently no, but it's probably not that hard to add support for it. The current workaround is to use type or property converter and implement such builder there, but that's not really a generic friendly way. And since the helper classes would have to be public... it's not a nice workaround. I've been postponing adding something along the line of builder to the CompiledJson annotation; that would solve you'r problem. |
So, I've looked at this... and... Supporting such builders with just a few annotations doesn't seem likely (due to various issues). |
FWIW this is now supported via reflection (no need for annotations, just matching signature): https://github.com/ngs-doo/dsl-json/blob/master/examples/Runtime/src/main/java/com/dslplatform/runtime/Example.java#L26 If someone wants to further improve immutables, basic analysis is done in: https://github.com/ngs-doo/dsl-json/blob/master/java8/src/main/java/com/dslplatform/json/runtime/ImmutableAnalyzer.java |
This now works via annotation processor as long as ctor is public. |
What if the immutable properties are in a superclass? e.g.:
|
I don't think it should matter. Can you write a test for that? Not sure if one exists. It will be useful if it works or if it doesn't work :) |
The following code fails to compile with 1.7.5.
|
I see. Tnx. Will add support for that in next version |
@ratcashdev your example should work in v1.8.0 |
Hai. Is there any example on working example of dsl-json with lombok/autovalue when using @CompiledJson (I am using builder pattern) |
@suraj1291993 sorry, I don't have one. But I can certainly help you resolve issues if you try to build one |
Hai, this is the lombok code, I am trying. But during compilation, dsl-json code is not getting generated.
For similar object constructed using AutoValue
I am getting the following exception during compile time
I am using Java 10,0.1 in intellij |
Hm... actually the builder pattern feature is still not supported, hence this issue is still open. I would guess the problem here is that Lombok is either running after the dsl-json or not copying the annotation to the concrete target. |
You can find the decompiled class here Can I know when you are planning to support builder pattern ? |
I'll look that it goes into 1.8.1 which hopefully will be done by this months end. |
Compile time support for builder pattern is working now. I don't plan on adding runtime support for that (at least not now). |
Hai, I wanted to try the latest development setup. But I am getting following exception. (I was using AutoValue)
|
You are probably trying to use DSL annotation processor. Try with Java8 version:
|
I am having dsl-json-1.8.1, dsl-json-java8-1.8.1 & dsl-json-processor-1.8.1 in my class path. I added dsl-json-1.8.1 also in path because of
When I am compiling, I am getting following errors.
and
Also, when I am using auto-value,
I am getting this error
Kindly, guide me on how should I change my code. |
Remove the dsl-json-processor dependency. Thats for the DSL annotation processor. You don't need that since there is a more feature rich version in the dsl-json-java8 dependency. |
I tried your suggestion, The autovalue example works fine. Thanks. For the lombok example, I am getting the error
and
|
Also, I tried using FreeBuilder. I am getting an error
The code snippet I used is
|
For Lombok I assume annotation processor is not run and it falls back to runtime probing since you've initialized DslJson using (Settings.withRuntime or something alike) Can you show me the generated code for this FreeBuilder? |
You can find generated code for FreeBuilder here |
Does this FreeBuilder works if you do
I can look into recognizing this kind of relationship during analysis. |
Even after trying suggestion, I am getting the same exception |
It would be great if you can add such test here: https://github.com/ngs-doo/dsl-json/blob/master/tests-java8/src/test/java/com/dslplatform/json/BuilderTest.java#L106 and make a PR. |
@suraj1291993 it should be working now: https://github.com/ngs-doo/dsl-json/blob/master/tests-java8/src/test/java/com/dslplatform/json/BuilderTest.java#L153 |
@azell FWIW this is now working in latest version. It's sufficient to add |
I would like to add dsl-json support to https://github.com/soabase/soabase-halva/blob/master/halva/src/main/java/io/soabase/halva/caseclass/README.md . halva generates immutable classes that are paired with builder classes. Jackson support for the builder pattern can be implemented with
@JsonDeserialize
.Example: https://github.com/soabase/soabase-halva/blob/master/examples/example-generated/JsonTestCase.java
Is there an equivalent way to specify a custom builder object with dsl-json? Default compilation results in:
The text was updated successfully, but these errors were encountered: