vert-x3 / vertx-service-proxy

EventBus Proxy generation
Apache License 2.0
67 stars 58 forks source link

when will it invoke #67

Closed okou19900722 closed 6 years ago

okou19900722 commented 6 years ago
private static <T> Map<String, T> convertMap(Map map) {
    if (map.isEmpty()) { 
      return (Map<String, T>) map; 
    } 
    Object elem = map.values().stream().findFirst().get(); 
    if (!(elem instanceof Map) && !(elem instanceof List)) { 
      return (Map<String, T>) map; 
    } else { 
      Function<Object, T> converter; 
      if (elem instanceof List) { 
        converter = object -> (T) new JsonArray((List) object); 
      } else { 
        converter = object -> (T) new JsonObject((Map) object); 
      } 
      return ((Map<String, T>) map).entrySet() 
       .stream() 
       .collect(Collectors.toMap(Map.Entry::getKey, converter::apply)); 
    } 
  }

this method in "proxygen.templ" but service method param Map only support Json or basic value,when will the converter invoker

sorry for bad english!I'm Chinese,Thank you

tsegismont commented 6 years ago

This method will be invoked in the generated code if a service method has a map parameter.

See https://github.com/vert-x3/vertx-service-proxy/blob/ecc1c64778702160d5a0eef34b4190f5121cbfc5/src/test/generated/io/vertx/serviceproxy/testmodel/TestServiceVertxEBProxy.java#L375

okou19900722 commented 6 years ago

@tsegismont but the value elem cannot be Map or List,the method 'checkParamType' in ProxyModel check Map code is

if (raw.getName().equals(List.class.getName()) || raw.getName().equals(Set.class.getName())) {
      TypeInfo argument = ((ParameterizedTypeInfo) type).getArgs().get(0);
      if (argument.getKind().basic || argument.getKind().json || argument.getKind() == ClassKind.DATA_OBJECT) {
        return true;
      }
    } else if (raw.getName().equals(Map.class.getName())) {
      TypeInfo argument0 = ((ParameterizedTypeInfo) type).getArgs().get(0);
      if (!argument0.getName().equals(String.class.getName())) {
        return false;
      }
      TypeInfo argument1 = ((ParameterizedTypeInfo) type).getArgs().get(1);
      if (argument1.getKind().basic || argument1.getKind().json) {
        return true;
      }
    }

Key must be String, and Value must be base or json

tsegismont commented 6 years ago

You are confusing two things:

tsegismont commented 6 years ago

@okou19900722 please follow-up on the Vert.x forum if you need more info. We do not use GitHub for questions. Thanks.

See (http://vertx.io/community)

okou19900722 commented 6 years ago

@tsegismont yes , but do you think a invalid param will compile success when annotation processor process?