dsl-json
dsl-json copied to clipboard
How to manually add DTO classes for compilation
Hi I have some DTOs in external libraries where I can not simple add @CompiledJson annotations to. How can I manually define a list of classes for which DSL json generates optimized serializers? I use Java8 version with maven and did not find any solution for this. Best regards Markus
You can create a class which references them and put annotation on it.
Ok, the problem now is that the referenced DTO class has Jackson annotations:
public class Event {
private final String id;
private final String name;
private final byte[] payload;
private final ZonedDateTime created;
private Event(String id, String name, byte[] payload, ZonedDateTime created) {
this.id = id;
this.name = name;
this.payload = payload;
this.created = created;
}
@JsonCreator
public static Event New(String id, String name, byte[] payload, ZonedDateTime created) {
return new Event(id, name, payload, created);
}
... (getters)
but DSL json seems to ignore @JsonCreator in this class. I reference it via:
@CompiledJson
public class JsonInit {
private Event event;
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
}
Any ideas to support this one?
Thanks for your effort :)
You can configure it to recognize some Jackson stuff. I think it should recognize JacksonCreator https://github.com/ngs-doo/dsl-json/blob/master/examples/Jackson/pom.xml#L40
Thanks for the fast support :) I created a test project here: https://github.com/doppelrittberger/dsljson-test But I cannot get it to compile. What am I missing?
Hi there,
one addition: if I delete the JsonInit class which references the Event class which is annotated with @JsonCreator it works. So I think there is a small bug in how the classes are generated. If I move CompiledJsonAnnotationProcessor Line 279 (process @CompiledJson annotation) below the processing of the Jackson/JsonB annotations (Line 285) my example works. Tests seem still to be working. Maybe you can add this fix if its working for you.
Thanks, Markus
Tnx. I'll look when I find some time
Finally found some time and fixed this bug: https://github.com/ngs-doo/dsl-json/commit/fabeaa2a59a7e2edf8f6c69247cd5b565f2088f6
v1.10 released