Forum Discussion

michael-reed-ha's avatar
5 years ago

Java code gen "incompatible types" generic list value

I am getting an error in java code gen for a map of String->String[] in java.

The swagger source definition:

DataMap:
description: Provides a generic map of string->string
additionalProperties:
$ref: '#/components/schemas/StringArray'
title: DataMap
type: object
StringArray:
description: String array
items:
type: string
title: StringArray
type: array

 Results in java code:

 

private Map<String, List<String>> dataMap = null;

  public RequestMetaData putDataMapItem(String key, List<String> dataMapItem) {

    if (this.dataMap == null) {

      this.dataMap = new HashMap<String, List>();

    }

    this.dataMap.put(key, dataMapItem);

    return this;

  }

This does not compile.  It fails with 

 

error: incompatible types: HashMap<String,List> cannot be converted to Map<String,List<String>>

 

This seems like a common definition structure.  Has anyone seen this/resolved it?

No RepliesBe the first to reply