dsl-json icon indicating copy to clipboard operation
dsl-json copied to clipboard

How to manually add DTO classes for compilation

Open doppelrittberger opened this issue 3 years ago • 6 comments

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

doppelrittberger avatar Jan 08 '22 22:01 doppelrittberger

You can create a class which references them and put annotation on it.

zapov avatar Jan 09 '22 08:01 zapov

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

doppelrittberger avatar Jan 09 '22 10:01 doppelrittberger

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

zapov avatar Jan 09 '22 10:01 zapov

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?

doppelrittberger avatar Jan 09 '22 11:01 doppelrittberger

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

doppelrittberger avatar Jan 13 '22 19:01 doppelrittberger

Tnx. I'll look when I find some time

zapov avatar Jan 14 '22 05:01 zapov

Finally found some time and fixed this bug: https://github.com/ngs-doo/dsl-json/commit/fabeaa2a59a7e2edf8f6c69247cd5b565f2088f6

zapov avatar Jan 04 '23 11:01 zapov

v1.10 released

zapov avatar Jan 07 '23 08:01 zapov