Skip to content
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

mapping multiple generic fields of different data-types gives type-erasure error #192

Open
nikhilvjain opened this issue Mar 6, 2018 · 2 comments
Labels
Milestone

Comments

@nikhilvjain
Copy link

Hi,
I'm using Selma 1.0 and I'm getting type-erasure error for the below mapping.
There's a simple generic class,

public class Value<T> {
	private T value;
	private String unit;
        //getter, setter
}

And I'm using the above class with multiple fields, which looks like,

public class Records {
	private Value<String> type;
	private Value<Double> speed;
        //getter, setter
}

And my mapper is,

@Mapper(withIoC = IoC.SPRING)
public interface RecordMapper {
	RecordsDAO asRecordsDAO(Records records);
}

And here is the Selma generated Class,

// GENERATED BY S3LM4
@org.springframework.stereotype.Service("")
public final class RecordMapperSelmaGeneratedClass
    implements RecordMapper {

  @Override
  public final RecordsDAO asRecordsDAO(Records inRecords) {
    demo.RecordsDAO out = null;
    if (inRecords != null) {
      out = new demo.RecordsDAO();
      out.setSpeed(asValue(inRecords.getSpeed()));
      out.setType(asValue(inRecords.getType()));
    }
    return out;
  }

  public final Value<String> asValue(Value<String> inString) {
    demo.Value<java.lang.String> out = null;
    if (inString != null) {
      out = new demo.Value<java.lang.String>();
      out.setUnit(inString.getUnit());
      out.setValue(inString.getValue());
    }
    return out;
  }

  public final Value<Double> asValue(Value<Double> inDouble) {
    demo.Value<java.lang.Double> out = null;
    if (inDouble != null) {
      out = new demo.Value<java.lang.Double>();
      out.setUnit(inDouble.getUnit());
      out.setValue(inDouble.getValue());
    }
    return out;
  }

  /**
   * Single constructor
   */
  public RecordMapperSelmaGeneratedClass() {
  }
}

The above conversion complains that,
SelmaRecordMapperSelmaGeneratedClass.java:[30,30] name clash: asValue(Value<java.lang.Double>) and asValue(Value<java.lang.String>) have the same erasure

This can be solved by adding CustomMapper but i've many such fields and dataTypes which clashes, so do we have a simple solution to this kind of problem?
for eg, instead of generating method name asValue(), can it also include the dataType along?
like asValueDouble(), asValueString() which can help in differentiating the methods?

slemesle added a commit that referenced this issue Mar 6, 2018
@slemesle
Copy link
Collaborator

slemesle commented Mar 6, 2018

Hi, I've just commited a fix extending the name of the generated in such case.
It will not work in all cases because the type argument is not properly resolved but it should work for you.

@slemesle slemesle added the bug label Mar 6, 2018
@slemesle slemesle added this to the 1.1 milestone Mar 6, 2018
@nikhilvjain
Copy link
Author

Thanks @slemesle , it works like charm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants