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
Lombok setter property AccessLevel.NONE is not working. #177
Comments
So the main problem is that DSL-JSON annotation processor picks up annotations from public getters and setters instead of private fields. While I'm not against introducing maven option to expand this behavior, it would be interesting to see if there is a way for Lombok to copy annotation to getter, which would make it DSL-JSON friendly. |
some config option is there that we can add in lombok.config is like below.
and its working also as its adding the JsonProperty on getter/setter methods but still not able to serialise/deserialise . but if I am writing getter method manually (without getter annotation from lombok) , its able to serialize |
@zapov any comments on above ?? |
I don't use Lombok so my knowledge about it is rather limited. Did you try copyableAnnotation for dsl-json JsonProperty? Jackson JsonProperty will work only if you enable its usage in Maven (I don't think it's enabled by default) |
"Did you try copyableAnnotation for dsl-json JsonProperty?" for DSL JsonAttribute you mean ?? "Jackson JsonProperty will work only if you enable its usage in Maven (I don't think it's enabled by default)" ??? I did not get this exactly , what kind of maven usage I need to enable ?? |
Yes, I meant dsl-json JsonAttribute. There is maven setting to enable Jackson attributes: https://github.com/ngs-doo/dsl-json/blob/master/examples/Jackson/pom.xml#L37 |
Thanks for quick reply but unfortunately lombok.copyableAnnotations += com.dslplatform.json.JsonAttribute is not working the maven settings provided by you is also not working :( |
What do you mean the Maven setting is not working? Anyway... I cant be of more help unless you copy paste what Lombok creates. That should point out the problem. |
model class `@AllArgsConstructor @JsonProperty(value = "new_key") what LOMBOK generates `@CompiledJson
} and what I am trying to run `public class Test { public static void main(String[] args) throws Exception {
} output is : {"newKey":null} {"newKey":null} and Lombok.config is and compiler plugin for maven `
|
seems like I found the issue , when we are running with @JsonProperty never works even if we manually add on getters/setters or generate using lombok because of following method call , final String name = Analysis.beanOrActualName(mget.getName()); which return fieldname but not the annotated value , based on this value we are calculating WeakHash. so please consider kind of below code which can be enhanced . Another overloaded method to be added in Analysis.Java with method signature as Method instead of String. you can have some flag to execute only if Jackson is enabled and try to get value from annotation if its not present the call public static String beanOrActualName(Method meth) { please let me know your thoughts :) |
Not really ;( You were testing runtime behavior of dsl-json which supports only a subset of features. While I don't have anything major against improving the runtime parity, its much better to rely on compile time setup, so I dont expect much demand for it. I don't have much time ATM, but I'll try to find some time to make a reproducible on the Lombok example and see whats going on. But again, please try to use JsonAttribute from dsl-json and setup Lombok to copy that attribute... which should minimize various confusions. |
Hi , why I don't want to switch from Jackson's JsonProperty to DSL JsonAttribute is
|
Mkay. Then I'll look why Jackson property would not be working. If you can create exact reproducible project that would be helpful... so I don't need to copy paste from here and setup stuff |
ok sure. I will give you reproducible example. |
This is having both issues ,
also If you compare Converter classes generated by DSL for both model class (with and without lombok) ,you will observe different quoted_field and named_field values for both converters. |
So there seems to be a problem with dsl-json that it's not picking up annotation info from setter method, only from getter. But on the other hand Lombok does not create annotation on getter, only on setter. |
Hi , I think Lombok is creating annotation on getter/setters both. if you take look at generated SimplePojoLombok.class in above sample project , you can see following : import com.dslplatform.json.CompiledJson; @CompiledJson
} which is generating annotations. on both getter/setter |
Thats not getting created for me.
|
its quite strange , I hope you are having following lombok dependency only.
and POM 's build is having following plugin org.apache.maven.plugins maven-compiler-plugin 3.7.0 1.8 |
I just opened the project in IntelliJ. Did not change anything with the setup. Anyway... you can see thats that the cause of problems by removing getter annotation from SimplePojo and having the TestSimplePojo.testCompileTime fails. Otherwise if there is annotation on getter it will succeed. btw. it is expected that dsl-json for runtime only fails, since it does not support that feature |
Ok following are things : // without Lombok scenario :
// with Lombok scenario : I am using - java 8 ( could you please try with same java version ). also can you confirm if this is enough for initialising dsl-json for compile time scenario or anything else is needed ?? |
There is some problem with your environment causing this issues. I just now ran
The runtime analysis does not look into annotations and extract info from there, such as custom attribute name. This is only implemented for compile time analysis. Yes, this should be sufficient (as this is the setup from tests). If I comment out those 3 problematic tests this is output I get
If you are getting anything else... thats something to look into |
Hi , those test cases are for reproducing the issue. Test class : TestSimplePojo.java - this will test simple Pojo's serialisation/deserialisation which is having @JsonProperty annotation on getter/setters manually added by me. TC-1 - testRuntime - this is to test simple Pojo's serialisation/deserialisation using runtime settings. Test class : TestSimplePojolombok.java - this will test SimplePojoLombok Pojo's serialisation/deserialisation which is having @JsonProperty annotation on getter/setters generated by Lombok. TC-3 - testRuntime - this is to test SimplePojoLombok Pojo's serialisation/deserialisation using runtime settings. from all 4 test cases , 3 were supposed to fail ( TC-1,TC-3,TC-4 which is reproducible example ). Now as you confirmed , "The runtime analysis does not look into annotations and extract info from there, such as custom attribute name. This is only implemented for compile time analysis." we can ignore/drop TC-1 and TC-3 (runtime settings scenario) for now. but still I am not sure why TC-4 is failing where annotation are getting generated using lombok but its failing . I am attaching project one more time where I have removed runtime test cases. Lets concentrate on compile time test case. The project which I am attaching now its having 2 test case :
Please open project in IntelliJ , do "clean install -DskipTests". once its build please check how the class is getting generated under target/test-classes - SimplePojoLombok.class if its having annotation above getter method then we are good else we will close this issue :(. Project - dslissue copy.zip |
Yes, I'm now seeing the same thing as you since you included I can only guess why it's not working... which would be that Lombok uses some strange method of code gen which is not getting picked up by annotation processor, or that this annotations are being created after the dsl-json annotation processor runs. Thing which you could try is to separate this pojo classes in model.jar and have Lombok set them up as expected. Thus if you create some dummy pojo in your project and annotate it with Again, I don't use Lombok much and don't know what magic it does, all I'm aware that they don't use the standard annotation processor infrastructure. Anyway, ideally there should be an option of dsl-json picking up annotations from private members of relevant getters which should resolve this issue. I'll look now how feasible is that... |
perfect , I was also testing one more scenario where similar to String as property inside model , I added StringBuffer property inside model ,while deserialising Json I did not find any issue but during serialisation Stringbuffer was not getting populated properly . Note : Again this is NOT Lombok generated properties but added manually and I am testing with Compile time settings . Attaching project again with test case. Test case : TestSimplePojo .java -> testCompileTimeWithStringBuffer please let me know if this is also issue |
Pushed a change which will now cause analysis of private members too. As for StringBuffer, there is only reader registered in the system, thus it's not getting picked up: https://github.com/ngs-doo/dsl-json/blob/master/library/src/main/java/com/dslplatform/json/DslJson.java#L587 |
Thanks , its working now 👍 , StringBuffer still I am trying to figure out as like other inbuilt classes , it should also work if we are not having any custom requirement. |
Hi @zapov , reopening issue because the original thing is still not solved. "Lombok setter property AccessLevel.NONE is not working." mostly the use case will be for following : @Setter(AccessLevel.NONE) // Lombok won't generate setter for this. // if we don't want Lombok then @JsonProperty("model_name") public getModel(){ NO SETTER METHOD FOR MODEL ( as its list , we want to add value inside list instead. of setting) in this case , if there are no setter methods available then we need to check for field if its of type (List or Set) and then add value in that collection accordingly instead of setting value. Please let me know your thoughts on this :) |
I think I only extended the case to support private fields for bean standard. It could be extended to support ctor arguments (should be a nice learning experience) |
Ah, you want to have lists without setters. Thats a different problem. dsl-json does not know how to handle this (although it doesn't seem like it would be difficult to support). It does require some additional hints/annotations for this ;( |
I actually compared both generated _DSL_converters files , I observed that compiler is not at all generating fields if setter method is not present. private static final byte[] quoted_buffer; I guess @Setter(AccessLevel.NONE) itself is enough hint for you understand that this field may be of type of collection and you can generate its setter or special method like serialzelist( <? extends Collections > list, T value) something like that , you can enable this functionality only if Lombok's @Setter(AccessLevel.NONE) annotation is present. if you want to extend this functionality to NON-Lombok methods then you can introduce one more flag inside your standard |
I guess having JsonProperty should indicate the desire for resolution and could cope with missing setter for collections. |
Thanks , I am keeping this issue open so that you can update me here once solution is available. |
This should work with latest commit. Although you will first need to add NonNull annotation on it |
v1.9.6 released |
HI ,
`@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@CompiledJson
public class TestList {
@JsonProperty("test_name")
@Setter(AccessLevel.NONE)
private List list = new ArrayList<>();
}`
and model class
`public Class Model {
@JsonProperty("test_field1")
@Setter(AccessLevel.NONE)
private String field1;
}`
2.Similar issue can be observed if only single field is having @Setter(AccessLevel.NONE) then I am not able to deserialise that property (field1).
Version -
com.dslplatform
dsl-json-java8
1.9.6
Thank you very much , I am trying to implement DSL because I have observed the speed compare to other libraries.
The text was updated successfully, but these errors were encountered: