Package com.jaxws.json.codec.decode

Examples of com.jaxws.json.codec.decode.WSJSONPopulator


public class WSJSONPopulatorTest extends TestCase {

  public void testPopulatePrimitive() throws Exception{
   
    WSJSONPopulator populator = new WSJSONPopulator(null, null, null, null, null);
    JSONReader r = new JSONReader();
    TestClass object = new TestClass();
    populator.populateObject(object, (Map) r.read("{\"name\":\"nm\"}"), null, null);
    assertEquals(object.name, "nm");
    assertEquals(object.values, null);
   
    populator.populateObject(object, (Map) r.read("{\"integer\":\"24\"}"), null, null);
    assertEquals(object.integer, 24);
    assertEquals(object.values, null);
  }
View Full Code Here


    assertEquals(object.values, null);
  }
 
  public void testList() throws Exception{
   
    WSJSONPopulator populator = new WSJSONPopulator(null, null, null, null, null);
    JSONReader r = new JSONReader();
    TestClass object = new TestClass();
    populator.populateObject(object, (Map) r.read("{\"values\":[\"nm\"]}"), null, null);
    assertEquals(object.name, null);
    assertEquals(object.values.size(), 1);
    assertEquals(object.values.get(0), "nm");
   
    // empty list
    populator.populateObject(object, (Map) r.read("{\"values\":[]}"), null, null);
    assertNotNull(object.values);
    assertEquals(object.values.size(), 0);
  }
View Full Code Here

          JSONCodec.globalMapValuePattern : Pattern.compile(jsonwebService.listMapValue()));
      //
     
      Map<String,Object>   operationParameters = (Map<String, Object>) invocationProperties.remove(JSONCodec.JSON_MAP_KEY);
     
      WSJSONPopulator   jsonPopulator     = new WSJSONPopulator((Pattern)invocationProperties.get(JSONCodec.globalMapKeyPattern_KEY),
          (Pattern)invocationProperties.get(JSONCodec.globalMapValuePattern_KEY),JSONCodec.dateFormat,
          codec.getCustomSerializer()
          ,(DebugTrace)invocationProperties.get(JSONCodec.TRACE));
     
      Object[]      parameterObjects  = new Object[operation.getInParts().size()];
      Class<?>[]       parameterTypes     = seiMethod.getParameterTypes();// This parameter types not trustable in case of HOLDER
      for(Map.Entry<String, WSDLPart> part : operation.getInParts().entrySet()){
        Class<?>     parameterType;
        if(context.getGlobalType(part.getValue().getDescriptor().name()) != null)
          parameterType = context.getGlobalType(part.getValue().getDescriptor().name()).jaxbType;
        else
          /*
           * This parameter types not trustable in case of HOLDER
           * We can't find it in global type once user extend simple type and use it as method parameter.
           * E.g String255 extended from String
           */
          parameterType = parameterTypes[part.getValue().getIndex()];
        if(!operationParameters.containsKey(part.getKey())){
          return new JSONMessage(null, operation, operationParameters, jsonPopulator);
                //throw new RuntimeException(String.format("Request parameter %s can't be null. B.P 1.1 vilation", part.getKey()));
              }
       
        Object val = null;
              if(!WSJSONPopulator.isJSONPrimitive(parameterType)){
                val = jsonPopulator.populateObject(jsonPopulator.getNewInstance(parameterType),
                    (Map<String,Object>)operationParameters.get(part.getKey()),jsonwebService,
                    (List<MIMEPart>) invocationProperties.get(JSONCodec.MIME_ATTACHMENTS));
              } else {
                val  = jsonPopulator.convert(parameterType, null, operationParameters.get(part.getKey()),
                    seiMethod != null ? seiMethod.getAnnotation(JSONWebService.class) : null, null);
              }
              parameterObjects[part.getValue().getIndex()] = val;
      }
     
      // TODO find better way with out using JavaMethodImpl
      List<ParameterImpl> requestParameters = ((JavaMethodImpl)javaMethod).getRequestParameters();
      List<ParameterImpl> responseParameters = ((JavaMethodImpl)javaMethod).getResponseParameters();
      invocationProperties.put(JSONEncoder.RESPONSEPARAMETERS, responseParameters);
     
      if(operation instanceof WSDLBoundOperationImpl && ((WSDLBoundOperationImpl)operation).getOutputMimeTypes().size() > 0){
        // Use only one in case of multipart use attachment
        String mimeType = String.valueOf(((WSDLBoundOperationImpl)operation).getOutputMimeTypes().values().toArray()[0]);
        for (Encoder handler : ServiceFinder.find(Encoder.class)) {
          if(mimeType.equals(handler.mimeContent())){
            invocationProperties.put(JSONCodec.ENCODER, handler);
            break;
          }
        }
      }
      if(requestParameters != null && requestParameters.size() == 1){
        ParameterImpl parameter = requestParameters.get(0);
        if(parameter.isWrapperStyle()){
          // RPC literal
          List<ParameterImpl> childParameters = ((WrapperParameter)parameter).getWrapperChildren();
          if(parameterObjects.length != childParameters.size())
            throw new RuntimeException("Invalid count of parameters");
          Object  obj  = null;
          if(style == Style.RPC){
            CompositeStructure cs = new CompositeStructure();
            cs.values  = parameterObjects;
            cs.bridges  = new Bridge[childParameters.size()];
            for(ParameterImpl parameterChild : childParameters){
              cs.bridges[parameterChild.getIndex()] = parameterChild.getBridge();
            }
            obj  = cs;
          }else{
            Class<?> type = (Class<?>)parameter.getBridge().getTypeReference().type;
            obj   = jsonPopulator.getNewInstance(type);
            for(ParameterImpl parameterChild : childParameters){
              type.getField(parameterChild.getPartName()).set(obj,
                  parameterObjects[parameterChild.getIndex()]);
            }
          }
View Full Code Here

TOP

Related Classes of com.jaxws.json.codec.decode.WSJSONPopulator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.