Skip to content

Missing generated field with supertype #172

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

Open
wilnguyen opened this issue Aug 23, 2020 · 2 comments
Open

Missing generated field with supertype #172

wilnguyen opened this issue Aug 23, 2020 · 2 comments

Comments

@wilnguyen
Copy link

wilnguyen commented Aug 23, 2020

I use Immutables to generate immutable DTOs. Everything works fine with DSL-JSON except List type field.
For example, i got this DTO

interface AbstractListDTO {
List getListField();
}

The generated file by Immutables look like

@CompiledJson
public final class ListDTO implements AbstractListDTO {
private final ImmutableList listField;
...
public ImmutableList getListField() {
return listField;
}
...
public static final class Builder
...
public final Builder listField(Iterable elements) {
this.listField = ImmutableList.builder();
return addAllListField(elements);
}

The generated _DslJsonConverter will miss that listField, even in Reflection mode too.

When i change the builder to accept ImmutableList instead of Iterable, it works fine and the _DslJsonConverter will contain that listField

public final Builder listField(ImmutableList elements) {
this.listField = ImmutableList.builder();
return addAllListField(elements);
}

Using Iterable make sense to me for a convenient builder. I wonder if DSL-JSON can support the builder with supertype in parameter like that?

@zapov
Copy link
Member

zapov commented Aug 23, 2020

It would need to be extended to support that use case, but I guess it could support it.

btw. can you configure the immutable to generate both methods for such lists.. so to make both you and dsl-json happy? That seems like easier workaround atm :)

@wilnguyen
Copy link
Author

wilnguyen commented Aug 23, 2020

can you configure the immutable to generate both methods for such lists
Currently I found no way to do this with Immutables. In my example, I copy and modify the generated code by hand just for testing.

For now, I replace all List/Set fields to array and it still work because array have param ... on the builder 😄
Fortunately, this happen only in the api layer, and all of my DTOs use MapStruct for automaticaly mapping fields, then List/Set or array is not a big deal, nothing gonna change on the logic code :D

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