GithubHelp home page GithubHelp logo

mapstruct / mapstruct-idea Goto Github PK

View Code? Open in Web Editor NEW
132.0 14.0 37.0 714 KB

An IntelliJ IDEA plugin for working with MapStruct

License: Other

Java 97.57% HTML 2.26% Kotlin 0.17%
mapstruct intellij java mapstruct-plugin mapping

mapstruct-idea's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapstruct-idea's Issues

Kotlin support for target / source in @Mapping and @ValueMapping

Currently the plugin only works in .java @Mapper classes (though it offers completions for source and target when referencing Kotlin classes as well!). It seems as if the plugin is simply not triggered in .kt mappers, but it works otherwise fine with Kotlin.

Kotlin Mapper interface:
Kotlin

Java Mapper interface:
Java

In both cases the DTO and model are Kotlin classes.

Versions used:

  • Kotlin 1.1.51
  • mapstruct 1.2.0.final
  • IntelliJ Community Edition 2017.2.3

Add quick fix for can't map property X to Y

The eclipse plugin has a quick fix for the error "Can't map property X prop to Y prop. Consider to declare/implement a mapping method ...".

I still am not sure if IntelliJ has a way to register a quick fix for a warning / error (this is how Eclipse handles this now)

Have equivalents to Eclipse error markers

It'd be great to see warnings/errors similar to the way it's done in Eclipse, i.e. with warning/error markers right on the mapper interface and its annotations, e.g. if a mapping method fails to map some target attributes or if a source() property is misspelled.

Find usages and renaming for constructor fields

I've been trying to make this work. However, there are some problems with the custom ConstructorParametersReferencesSearcher that I've implemented. Find usages works properly. However, that causes some other problems:

  • When I rename the constructor parameter in the constructor method then my element in the annotation is not renamed. This is tested by MapstructMethodUsagesSearcherTest.testRenameConstructorTargetReferenceMethod
  • When I rename the element in the annotation and the class is in the same file as my annotation there is an error happening. This is tested in RenameHandlerTest.testRenameConstructorTargetParameter. When I run the plugin in an IDE and the class is not in the same file as my annotation then the renaming is correct.

Unmapped target properties when using meta annotation

When some fields will be ignored via meta-annotation the IDEA plugin still gives a hint that there are some unmapped target properties.

Untested example:

public class Source { }

public class Target {
  private String target;
}

@Mapping(target = "target", ignore = true)
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
public @interface IgnoreTarget { }

@Mapper
public interface TargetMapper {
  @IgnoreTarget
  Target toTarget(Source source); // IDEA adds a hint: unmapped target properties: target
}

Quick fixes - Fix all '...' problems in file

With the quick fix there comes the "Fix all 'Unmapped target properties' problems in file" option. But this only fixes the selected target property and not all as it should. Also it is not clear if fix all means add all or ignore all properties.

  1. the fix all should go through the list of all similar problems
  2. all similar should make a difference between add and ignore, depending on what menu entry was selected

I recognized that there is an "Ignore all unmapped target properties". That helps on the first level in the menu but the "Fix all..." in the submenu is also a common usage in IntelliJ IDEA. At least having the same for add would be a quick win while completing the implentation to Fix all later on.

Refresh of generated mapper not working reliably

When altering a mapped type (e.g. the target type of a mapping method), mappers referring to that type aren't re-generated reliably.

I couldn't quite figure when it's working and when not, often I had to explicitly rebuild the entire project. I'd assume there's a way in IntelliJ plug-ins to mark a type (a mapper type) as dependent on other types (the source and target types of the mapper's methods), so a re-generation can be triggered in such case.

Mapping of Enum with public static method false Unmapped target property warning

Hi,

I have a mapping from source enum to target. My target enum looks like this:

public enum AccountTypeEnum {
    CUSTOMER("customer"),
    
    BILLING("billing"),
    
    SERVICE("service"),
    
    HOUSEHOLD("household");

    private String value;

    AccountTypeEnum(String value) {
      this.value = value;
    }

    @Override
    @JsonValue
    public String toString() {
      return String.valueOf(value);
    }

    @JsonCreator
    public static AccountTypeEnum fromValue(String text) {
      for (AccountTypeEnum b : AccountTypeEnum.values()) {
        if (String.valueOf(b.value).equals(text)) {
          return b;
        }
      }
      return null;
    }
  }

The problem is, that I get a warning: Unmapped target property: fromValue while it is a public static method and not a property.
I get this warning only in the mapstruct-idea plugin. Mapstruct itself doesn't give this warning while compilation.

Unmapped field when the field name starts with 'set' and Lombok @Builder is used

MapStruct Support: v1.1.1
MapStruct 1.3.0.Final
Lombok: 1.8.8
Java: openjdk version "11.0.2" 2019-01-15
Gradle: 5.4.1

We use MapStruct to map Java objects and Avro objects.
In one object there is one field that is not mapped from Avro to Java (the other way works).
This seems to be an issue only in Intellij because the test works when I run it with Gradle.

When I compare the generated ...MapperImpl.java from Intellij and Gradle I see that Intellij is using the .builder() from Lombok and Gradle uses the default constructor and then calls the setters (mapstruct/mapstruct#1742).

I think the issue is that the field starts with 'set' like 'settlement' which is already a known issue in MapStruct (mapstruct/mapstruct#1799). The Lombok builder just uses the field name as method name and MapStruct removes the 'set' so this ends up in 'tlement' which has no corresponding field in Avro. Because of that the generated ...MapperImpl.java never calls .settlement() on the builder.

Avro also generates a builder but it is prefixing the methods with 'set' (setSettlement) and thus it is not an issue mapping from Java to Avro

idea plugins question

idea plugins

config
idea version 2020.2
mapstruct 13.1.Final
gradle 6.+

describe
I converted the implementation of inheriting abstract class in mapper. When the plug-in compiles automatically, an error is reported and the file disappears

public abstract class CommonPO implements Serializable, Cloneable {}
@DaTa public class TenantPO extends CommonPO {}
@DaTa public class TenantDTO {}
@Mapper
public interface TenantConvert { TenantPO tenantDTOToTenantPO(TenantDTO tenantDTO); }

Mapping enum with methods causes IDEA missing target mapping warnings that aren't valid

Given a Java enum:

public enum Bar {
  ALPHA,
  BETA;

  public static Bar fromNumber(int i) {
    return ALPHA;  // keep compiler smiling
   }
}

and a similar enum:

public enum Foo {
  ALPHA,
  BETA;
}

and a simple mapping between them:

@Mapper
public interface MyMapper {
  MyMapper INSTANCE = Mappers.getMapper(MyMapper.class);

  Bar map(Foo source);
}

IntelliJ shows a warning for the map method: Unmapped target property: fromNumber. This is incorrect (and MapStruct's annotation processor does not warn about this).

Having the IDEA plug-in add

  @Mapping(target = "fromNumber", ignore = true)

causes the annotation processor to fail with the very correct error A source constant must be specified for mappings of an enum mapping method.

It appears that the IDEA plug-in is incorrectly treating the fromNumber method as one of the enum's constant values. It should filter out things like methods.

Plug-in version is the latest (1.1.1).

Incorrect "unmapped property" warning with inheritance

We have some internal messages which extend a BaseClass. This BaseClass contains some variables for our database. These variables should be present in our DTOs.
To avoid ignoring the variables in every single mapper we're using a GenericConfig. In the GenericConfig no warnings were displayed. Neither when we compile the code nor at the IDE level.
Our GenericConfig looks like the following:

@MapperConfig(uses = DateToOffsetDateMapper.class,
        unmappedTargetPolicy = ReportingPolicy.ERROR,
        mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface GenericConfig {

    @Mapping(target = "storageId", ignore = true)
    @Mapping(target = "date", ignore = true)
    BaseClass genericMessageMapping(GenericDto dto); 
}

The GenericDto is an empty interface. All DTOs implements this interface.

The BaseClass looks like the following:

public class BaseClass
{
   private String storageId;
   private OffsetDateTime date;

   //getter and setter
}

Every mapper extends this config.

@Mapper(config = GenericConfig.class, uses = {})
public interface CarMapper  {
   Car map(CarDto dto);
}

In this example Car extends BaseClass and CarDto extends GenericDto.
Now my question: Why does the IDEA plugin shows me the error that I have unmapped properties at Car map(CarDto dto)?
If I compile the code no warnings are shown, which I think is correct.

Maybe you have an idea where I have to look.

Class cast exception in MapStruct Support plugin.

Mapstruct Plugin 1.2.1

IntelliJ IDEA 2020.1.2 (Ultimate Edition)
Build #IU-201.7846.76, built on June 1, 2020
Licensed to **********
Subscription is active until September 23, 2020
Runtime version: 11.0.7+10-b765.53 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Linux 5.4.0-40-generic
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 24
Non-Bundled Plugins: GenerateSerialVersionUID, Lombook Plugin, org.mapstruct.intellij, MavenRunHelper, org.jetbrains.kotlin, cn.wuzhizhan.plugin.mybatis
Current Desktop: ubuntu:GNOME

Stack trace:

java.lang.ClassCastException: class com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl cannot be cast to class com.intellij.psi.PsiMethod (com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl and com.intellij.psi.PsiMethod are in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @18f7cdd9)
	at org.mapstruct.intellij.expression.JavaExpressionInjector.getLanguagesToInject(JavaExpressionInjector.java:94)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl.processInPlaceInjectorsFor(InjectedLanguageManagerImpl.java:423)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.probeElementsUp(InjectedLanguageUtil.java:345)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.enumerate(InjectedLanguageUtil.java:164)
	at com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl.enumerateEx(InjectedLanguageManagerImpl.java:321)
	at com.intellij.codeInsight.daemon.impl.InjectedGeneralHighlightingPass.lambda$getInjectedPsiFiles$3(InjectedGeneralHighlightingPass.java:184)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:149)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:162)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:162)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:162)
	at com.intellij.concurrency.ApplierCompleter.execAndForkSubTasks(ApplierCompleter.java:162)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1106)
	at com.intellij.concurrency.ApplierCompleter.lambda$wrapInReadActionAndIndicator$1(ApplierCompleter.java:105)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:627)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:572)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
	at com.intellij.concurrency.ApplierCompleter.wrapInReadActionAndIndicator(ApplierCompleter.java:117)
	at com.intellij.concurrency.ApplierCompleter.lambda$compute$0(ApplierCompleter.java:96)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:168)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:168)
	at com.intellij.concurrency.ApplierCompleter.compute(ApplierCompleter.java:96)
	at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)

Compiler warning with a default method

  • mapstruct 1.2.0.Final
  • mapstruct-idea 1.1.0

When I define a default method in the interface, the warning message as following will be shown.

Unmapped target properties: xxx

Publish to intellij repo

Hi

Thanks for the plugin. It would be much useful for everyone if this plugin can be pushed to the intellij repo instead of manual builds by everyone

Add smart completion for ValueMapping

Smart completion for @ValueMapping annotation means that the suggested values are not used in the other @ValueMapping annotations for this method.

String index out of range: -1

String index out of range: -1
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at java.lang.String.substring(String.java:1931)
	at org.mapstruct.intellij.util.MapstructUtil.getPropertyName(MapstructUtil.java:119)
	at org.mapstruct.intellij.util.MapstructUtil.getPropertyName(MapstructUtil.java:113)
	at org.mapstruct.intellij.search.MappingMethodUsagesSearcher.lambda$processQuery$0(MappingMethodUsagesSearcher.java:67)
	at com.intellij.openapi.project.DumbService.lambda$runReadActionInSmartMode$0(DumbService.java:91)
	at com.intellij.openapi.project.DumbService.runReadActionInSmartMode(DumbService.java:119)
	at com.intellij.openapi.project.DumbService.runReadActionInSmartMode(DumbService.java:91)
	at org.mapstruct.intellij.search.MappingMethodUsagesSearcher.processQuery(MappingMethodUsagesSearcher.java:62)
	at org.mapstruct.intellij.search.MappingMethodUsagesSearcher.processQuery(MappingMethodUsagesSearcher.java:48)
	at com.intellij.openapi.application.QueryExecutorBase.execute(QueryExecutorBase.java:87)
	at com.intellij.util.ExecutorsQuery.processResults(ExecutorsQuery.java:45)
	at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:79)
	at com.intellij.util.MergeQuery.processSubQuery(MergeQuery.java:85)
	at com.intellij.util.MergeQuery.forEach(MergeQuery.java:57)
	at com.intellij.util.UniqueResultsQuery.process(UniqueResultsQuery.java:66)
	at com.intellij.util.UniqueResultsQuery.forEach(UniqueResultsQuery.java:56)
	at com.intellij.util.UniqueResultsQuery.findAll(UniqueResultsQuery.java:79)
	at com.intellij.find.findUsages.JavaFindUsagesHandler.findReferencesToHighlight(JavaFindUsagesHandler.java:273)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.a(IdentifierHighlighterPass.java:163)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.getHighlightUsages(IdentifierHighlighterPass.java:140)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.a(IdentifierHighlighterPass.java:196)
	at com.intellij.codeInsight.daemon.impl.IdentifierHighlighterPass.doCollectInformation(IdentifierHighlighterPass.java:107)
	at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:70)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.b(PassExecutorService.java:438)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1148)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.d(PassExecutorService.java:431)
	at com.intellij.openapi.progress.impl.CoreProgressManager.a(CoreProgressManager.java:548)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:94)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.c(PassExecutorService.java:430)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.a(PassExecutorService.java:406)
	at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:142)
	at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:237)
	at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:404)
	at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:165)
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Version: 1.0.0
IntelliJ IDEA 2017.2.5
Build #IU-172.4343.5, built on September 19, 2017
JRE: 1.8.0_152-release-915-b12 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.12.6

Converter implementation is not refreshed in IDEA

Using https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-lombok as a reference, I tried to add a field to both Source and Target and then modified the test to cover the new field.

@Test
public void testMapping() {
    Source s = new Source();
    s.setTest( "5" );
    s.setField( "5" );

    Target t = Mappers.getMapper(SourceTargetMapper.class).toTarget( s );
    assertEquals( 5, (long) t.getTesting() );
    assertEquals( "5", t.getField() );
}

However this leads to the test to fail, being t.getField() still null.

Another relevant change I did (which I am not sure about) is to add mapstruct-processor to the compile configuration in build.gradle, ie: compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}", "org.mapstruct:mapstruct-processor:${mapstructVersion}", "org.projectlombok:lombok:${lombokVersion}" as per http://mapstruct.org/documentation/ide-support/

Also removing a field from both objects leads to an error, this time a java.lang.NoSuchMethodError.

Versions used:

  • IDEA 2017.2.5 (with annotation processor manually enabled, no other customization)
  • lombok 1.16.18 (instead of 1.16.14)

Bug: smart completion doesn't work for "target" with Lombok @SuperBuilder

Hi,
Thank you for great plugin! ๐Ÿ‘๐Ÿ‘๐Ÿ‘
It's really helpful during daily development.

I noticed that Mapstruct IDEA plugin doesn't support auto-completion for target attribute in @Mapping for latest mapstruct library.
However, auto-completion perfectly works for source attribute.

I have following setup and dependencies:

  • IntelliJ IDEA 2019.2.4
  • MapStruct Support IDEA plugin v. 1.1.1
  • org.mapstruct:mapstruct:1.3.1.Final
  • org.projectlombok:lombok:1.18.12

I noticed that Mapstruct Support stopped suggesting auto-completion after I upgraded mapstruct 1.2.0.Final -> 1.3.1.Final.

Want to refer to other mappers in customized mapping

I am able to generate mapping having component model as spring and refer to other mappers by adding, for example, @Mapper(uses = CoordinateMapper.class). This CoordinateMapper will map coordinate POJO and return latitude-longitude value.

However, I want to create a mapping such that, before mapping, it needs to verify that the given coordinate is in the valid area or not. If not in the valid area, just return default value, and if in valid area, return that value.

This is what I have
public class Business {
Coordinate coordinate;
}

public class BusinessDTO {
CoordinateDTO coordinate;
}

public class Coordinate {
double latitude;
double longitude;
}

public class CoordinateDTO {
double latitude;
double longitude;
}

@mapping(componentModel = "spring")
public interface BusinessMapper {
BusinessDTO toDTO(Business business);

default CoordinateDTO getCoordinate(Coordinate coordinate) {
if (valid(coordinate)) {
return getCoordinateMapper().toDTO(coordinate);
}
return defaultCoordinate;
}
}

@mapping(componentModel = "spring")
public interface CoordinateMapper {
CoordinateDTO toDTO(Coordinate coordinate);
}

The problem is I don't know how to getCoordinateMapper(). One way is to use Mappers.getMapper(CoordinateMapper.class) but actually my coordinateMapper must refer to other mappers as well. Using Mappers.getMapper(CoordinateMapper.class) makes the referred mappers null, and causes NullPointerException.

Any suggestions how to deal with this?

Support for Immutables builders

Hi,

I use mapstruct namely by mapping with some Immutables. Mapstruct deals correctly with auto-generated builders.
It would be nice if the plug-in could propose auto-completion given the builders.

ClassCastException using expression in Mappings

When we have a mapper defined like:

@Mapper
public interface MyMapper {

    @Mappings(
        @Mapping(target = "target", expression="java(<caret>)")
    )
    Target map(Source source);
}

then there is an exception:

java.lang.ClassCastException: class com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl cannot be cast to class com.intellij.psi.PsiMethod (com.intellij.psi.impl.source.tree.java.PsiNameValuePairImpl and com.intellij.psi.PsiMethod are in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @4fdd308f)
    at org.mapstruct.intellij.expression.JavaExpressionInjector.getLanguagesToInject(JavaExpressionInjector.java:94)
    at com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl.processInPlaceInjectorsFor(InjectedLanguageManagerImpl.java:423)
    at com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil.probeElementsUp(InjectedLanguageUtil.java:345)

New Version 1.1.1

Could you release this plugin in the version 1.1.1 I see that you fixed my reported bug?

Overridden method is suggested twice

For example:

public interface Id {

    String getId();
}

public interface Source extends Id {

    @Override
    String getId();
}

The id property will be suggested twice

Use the AccessorNamingStrategy during the auto-completion proposals

Apparently the intellij scala plugin has a feature called worksheet that is able to compile and read user code. This could be the approach for using the user defined AccessorNamingStrategy in order to provide better auto completion support.

There is an intellij-scala channel on gitter where we could ask more info

unmapped target property with custom method in mapper

Hi,
I have the following mapper method:

@Mapping(target = "name", ignore = true)
default CategoryRef mapProductCategoriesEnumToCateforyRef(ProductCategoriesEnum productCategoriesEnum){
    return new CategoryRef().id(productCategoriesEnum.toString());
}

while CategoryRef has 2 fields id and name. We ignore name via annotation and map only id manually as you can see in the code.

In this case we have a warning Unmapped target property: id. We actually map the id so why is it necessary to add annotation to ignore id too?
It seems weird to add it there while it is actually mapped.

Thanks.

unmapped target property boolean with is prefix

Hi,

I have the following mapper:

@Mapping(target = "isAdded", constant = "true")
@Mapping(target = "categories", source = "productCategories")
AddedService mapManageableAssetToAddedService(ManageableAsset manageableAsset);

while the target model AddedService (it is generated from swagger) has a the following field and getter/setter:

@JsonProperty("isAdded")
private Boolean isAdded = null;

public AddedService isAdded(Boolean isAdded) {
    this.isAdded = isAdded;
    return this;
}

/**
 * if true, used to mark services added to profile
 * @return isAdded
**/
@ApiModelProperty(value = "if true, used to mark services added to profile")
public Boolean getIsAdded() {
    return isAdded;
}

public void setIsAdded(Boolean isAdded) {
    this.isAdded = isAdded;
}

In this situation the idea plugin says Unmapped target property: added
(The situation is the same if the source model contains same field and same methods.)

It looks that the "fluent" method public AddedService isAdded(Boolean isAdded) causes the problem.

Can You fix this?

Thanks

Inspection to highlight incorrect @Mapping values

It would be great if the plugin could highlight incorrect mappings with an error directly in the editor.

An inspection would be a good way to implement that I think. (For example the user can then enable/disable it, configure the severity and supress it at specific occurrences if needed.)

Compiler warning in decorator

Hi There

I use the newest mapStruct 1.3.0.Beta2 in my project along with your mapStruct plugin for IntelliJ. I use a mapStruct dercorator to do some post mapping stuff. Wenn using the plugin I see a compiler error in the decorator class "@Mapper or @MapperConfig annotation missing...". But in the documentation of mapStruct is stated that there is no annotation needed in a decorator. (see http://mapstruct.org/documentation/stable/reference/html/#customizing-mappers-using-decorators)

Thank for the help

Feature request: add all unmapped properties

Currently when there are unmapped properties you have the option to add or ignore each unmapped property individually, it would be nice to be able to add all unmapped properties at once.

Refactor-rename a field breaks mapping when also using lombok

When I refactor-rename a field (and its getter) using IDEA, then the mapping annotation is changed incorrectly.

For example when I rename a field from foo to bar, then the target/source value in the mapping annotation is changed from foo to getBar.

You can reproduce this with the included "mapstruct-lombok" example:
Rename Source.test to Source.foo and the Mapping in SourceTargetMapper will incorrectly be

@Mapping( source = "getFoo", target = "testing" )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.