Mapstruct define a size in some maps

158 Views Asked by At

I have days trying to find a solution with a mapping but I'm at a point that I no longer know what to do, it seems that assigns a space to the maps at the time of mapping and this generates problems later ....

Is it possible to define not to instantiate a default size in the maps with Mapstruct ?

I have my mapper:

@Mapper(config = BaseMappingConfig.class)
public interface CarMapper  extends convertCarToAnother {

  @Override
  Car fromCarToBus(Car car);
}

When compiling I can see in the implementation that I have several LinkedHashMap and everything so far OK, but here I see something strange:

public class CarMapperImpl  implement CarMapper {

    
    public Car fromCarToBus(Car car) {
       
        Car car1 = Car.builder();

        if ( car != null ) {
            car1.setObjectOne( car.getObjectOne() );
            car1.setObjectTwo( stringObjectTwoToStringObjectTwo( car.getObjectTwo() ) );
            Map<String, Object> map = car.getMyMap();
            if ( map != null ) {
                car1.setMyMap( new LinkedHashMap<String, Object>( map ) );
            }
        }
        return car1.build();
    }

  }



protected Map<String, ObjectTwo> stringObjectTwoToStringObjectTwo(Map<String, ObjectTwo> map) {
        if (map == null) {
            return null;
        } else {
            Map<String, ObjectTwo> map1 = new LinkedHashMap(Math.max((int)((float)map.size() / 0.75F) + 1, 16));
            Iterator var1 = map.entrySet().iterator();
           //More code for add info in map1...
            return map1;
        }
    }

My problem is in the stringMethodTwoToStringMethodTwo method. Why it creates the LinkedHashMap with a space? Map<String, ObjectTwo> map1 = new LinkedHashMap(Math.max((int)((float)map.size() / 0.75F) + 1, 16));??? Because in car1.setMyMap( new LinkedHashMap<String, Object>( map ) ); yes it does it right and in the stringObjectTwoToStringObjectTwo method it creates a LinkedHashMap instance with a particular size? this may not look like a problem, but when I use then Pdx to serialize/deserialize I have problems, if I test removing by creating a new instance without the ObjectTwo, I get no error from Pdx.

I'm using 1.5.3.Final version

0

There are 0 best solutions below