Examples of JSONConverter


Examples of com.antiaction.common.json.annotation.JSONConverter

    int level;
    JSONNullable nullable;
    boolean bNullable;
    JSONNullValues nullValues;
    boolean bNullValues;
    JSONConverter converter;
    JSONName jsonName;
    try {
      for ( int i=0; i<fields.length; ++i ) {
        field = fields[ i ];
        // debug
        //System.out.println( field.getName() );
        bIgnore = json_om.ignore.contains( field.getName() );
        ignore = field.getAnnotation( JSONIgnore.class );
        if ( ignore != null ) {
          // debug
          //System.out.println( "ignore" );
          bIgnore = true;
        }
        if ( !bIgnore ) {
          fieldModsMask = ClassTypeModifiers.getFieldModifiersMask( field );
          // debug
          //System.out.println( field.getName() + " - " + ClassTypeModifiers.toString( fieldModsMask ) );
          bIgnore = (fieldModsMask & JSONObjectMappingConstants.FIELD_IGNORE_TYPE_MODIFIER) != 0;
        }
        if ( !bIgnore ) {
          fieldType = field.getType();
          fieldTypeName = fieldType.getName();
          classTypeMask = ClassTypeModifiers.getClassTypeModifiersMask( fieldType );
          // debug
          //System.out.println( fieldTypeName + " " + ClassTypeModifiers.toString( classTypeMask ) );

          type = JSONObjectMappingConstants.typeMappings.get( fieldTypeName );
          fieldObjectMapping = null;
          if ( type == null ) {
            if ( (classTypeMask & JSONObjectMappingConstants.FIELD_INVALID_TYPE_MODIFIERS_MASK) != 0 ) {
              throw new JSONException( "Unsupported field class type." );
            }
            classTypeMask &= JSONObjectMappingConstants.FIELD_VALID_TYPE_MODIFIERS_MASK;
            if ( (classTypeMask == JSONObjectMappingConstants.VALID_CLASS) || (classTypeMask == JSONObjectMappingConstants.VALID_MEMBER_CLASS) ) {
              Type genericType = field.getGenericType();
              //System.out.println( "GT: " + genericType + " " + genericType.getClass() );

              type = JSONObjectMappingConstants.T_OBJECT;
              // Cache
              fieldObjectMapping = classMappings.get( fieldTypeName );
              if ( fieldObjectMapping == null ) {
                fieldObjectMapping = mapClass( Class.forName( fieldTypeName, true, clazz.getClassLoader() ) );
              }

              if( genericType instanceof ParameterizedType ) {
                ParameterizedType parameterizedType = (ParameterizedType)genericType;
                Type[] typeArguments = parameterizedType.getActualTypeArguments();
                for ( Type typeArgument : typeArguments ) {
                  Class<?> classType = ((Class<?>)typeArgument);
                  //System.out.println( "Field " + field.getName() + " has a parameterized type of " + classType.getSimpleName() );
                }
              }
            }
            else if ( classTypeMask == JSONObjectMappingConstants.VALID_ARRAY_CLASS ) {
              type = JSONObjectMappingConstants.T_ARRAY;
              arrayType = JSONObjectMappingConstants.arrayTypeMappings.get( fieldTypeName );
              if ( arrayType == null ) {
                level = 0;
                while ( level < fieldTypeName.length() && fieldTypeName.charAt( level ) == '[' ) {
                  ++level;
                }
                // [L<class>;
                if ( level == 1 && level < fieldTypeName.length() && fieldTypeName.charAt( level ) == 'L' && fieldTypeName.endsWith( ";" ) ) {
                  arrayType = JSONObjectMappingConstants.T_OBJECT;
                  fieldTypeName = fieldTypeName.substring( level + 1, fieldTypeName.length() - 1 );
                  fieldType = Class.forName( fieldTypeName, true, clazz.getClassLoader() );
                  // Cache
                  fieldObjectMapping = classMappings.get( fieldTypeName );
                  if ( fieldObjectMapping == null ) {
                    fieldObjectMapping = mapClass( fieldType );
                  }
                }
                else {
                  throw new JSONException( "Unsupported array type '" + fieldTypeName + "'." );
                }
              }
            }
            else {
              throw new JSONException( "Unsupported field class type." );
            }
          }
          // debug
          //System.out.println( type );

          if ( type != null ) {
            json_fm = new JSONObjectFieldMapping();
            json_fm.fieldName = field.getName();
            json_fm.type = type;
            json_fm.arrayType = arrayType;
            json_fm.className = fieldTypeName;
            json_fm.clazz = fieldType;
            json_fm.objectMapping = fieldObjectMapping;
            json_fm.field = clazz.getDeclaredField( json_fm.fieldName );
            json_fm.field.setAccessible( true );

            bNullable = json_om.nullableSet.contains( json_fm.fieldName );
            if ( !bNullable ) {
              nullable = field.getAnnotation( JSONNullable.class );
              if ( nullable != null ) {
                bNullable = nullable.value();
              }
            }
            if ( bNullable ) {
              if ( json_fm.type < JSONObjectMappingConstants.T_OBJECT ) {
                throw new JSONException( "Primitive types can not be nullable." );
              }
              json_fm.nullable = true;
            }
            bNullValues = json_om.nullValuesSet.contains( json_fm.fieldName );
            if ( !bNullValues) {
              nullValues = field.getAnnotation( JSONNullValues.class );
              if ( nullValues != null ) {
                bNullValues = nullValues.value();
              }
            }
            if ( bNullValues ) {
              if ( json_fm.type >= JSONObjectMappingConstants.T_ARRAY && json_fm.arrayType < JSONObjectMappingConstants.T_OBJECT ) {
                throw new JSONException( "Array of primitive type can not have null values." );
              }
              json_fm.nullValues = true;
            }
            converter = field.getAnnotation( JSONConverter.class );
            if ( converter != null ) {
              json_fm.converterName = converter.name();
              Integer converterId = converterNameIdMap.get( json_fm.converterName );
              if ( converterId == null ) {
                converterId = converterIds++;
                converterNameIdMap.put( json_fm.converterName, converterId );
              }
View Full Code Here

Examples of net.thucydides.core.reports.json.JSONConverter

        }

    }

    public String toJson() {
        JSONConverter jsonConverter = Injectors.getInjector().getInstance(JSONConverter.class);
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            jsonConverter.toJson(this, outputStream);
            return outputStream.toString();
        } catch (IOException e) {
            return "";
        }
    }
View Full Code Here

Examples of railo.runtime.converter.JSONConverter

    // Params
    Map<String, String> params=new HashMap<String, String>();
    params.put("method",methodName);
    params.put("returnFormat","json");
    try {
      params.put("argumentCollection",new JSONConverter(true).serialize(pc, args, false));
   
   
      HTTPResponse res = HTTPEngine4Impl.post(
        HTTPUtil.toURL(url,true),
        client.getServerUsername(),
View Full Code Here

Examples of railo.runtime.converter.JSONConverter

          String strQF=((String) queryFormat).trim();
          if(strQF.equalsIgnoreCase("row"));
          else if(strQF.equalsIgnoreCase("column"))byColumn=true;
          else throw new ApplicationException("invalid queryformat definition ["+strQF+"], valid formats are [row,column]");
        }
        JSONConverter converter = new JSONConverter(false);
        String prefix="";
        if(props.secureJson) {
          prefix=pc.getApplicationContext().getSecureJsonPrefix();
          if(prefix==null)prefix="";
        }
        pc.forceWrite(prefix+converter.serialize(pc,rtn,byColumn));
    }
    // CFML
    else if(UDF.RETURN_FORMAT_SERIALIZE==props.format) {
      ScriptConverter converter = new ScriptConverter(false);
      pc.forceWrite(converter.serialize(rtn));
    }
      // XML
    else if(UDF.RETURN_FORMAT_XML==props.format) {
      XMLConverter converter = new XMLConverter(pc.getTimeZone(),false);
            converter.setTimeZone(pc.getTimeZone());
            pc.forceWrite(converter.serialize(rtn));
    }
    // Plain
    else if(UDF.RETURN_FORMAT_PLAIN==props.format) {
      pc.forceWrite(Caster.toString(rtn));
    }
View Full Code Here

Examples of railo.runtime.converter.JSONConverter

    }
   
        // JSON
    else if(UDF.RETURN_FORMAT_JSON==format) {
          boolean byColumn = false;
        JSONConverter converter = new JSONConverter(false);
        String str = converter.serialize(pc,rtn,byColumn);
            cs = getCharset(pc);
            is = new ByteArrayInputStream(str.getBytes(cs));
       
        }
        // CFML
    else if(UDF.RETURN_FORMAT_SERIALIZE==format) {
      ScriptConverter converter = new ScriptConverter(false);
      String str=converter.serialize(rtn);
            cs = getCharset(pc);
            is = new ByteArrayInputStream(str.getBytes(cs));
    }
      // XML
    else if(UDF.RETURN_FORMAT_XML==format) {
      XMLConverter converter = new XMLConverter(pc.getTimeZone(),false);
            converter.setTimeZone(pc.getTimeZone());
            String str=converter.serialize(rtn);
            cs = getCharset(pc);
            is = new ByteArrayInputStream(str.getBytes(cs));
    }
    // Plain
    else if(UDF.RETURN_FORMAT_PLAIN==format) {
View Full Code Here

Examples of railo.runtime.converter.JSONConverter

  public static String call(PageContext pc, Object var) throws PageException {
      return call(pc,var,false);
  }
  public static String call(PageContext pc, Object var,boolean serializeQueryByColumns) throws PageException {
    try {
            return new JSONConverter(true).serialize(pc,var,serializeQueryByColumns);
        } catch (ConverterException e) {
            throw Caster.toPageException(e);
        }
    //throw new FunctionNotSupported("SerializeJSON");
  }
View Full Code Here

Examples of railo.runtime.converter.JSONConverter

   
   
    String str;
    try {
      if(UDF.RETURN_FORMAT_JSON==argumentsCollectionFormat)  {
        str = new JSONConverter(true).serialize(pc,args,false);
        formfields.put("argumentCollectionFormat", "json");
      }
      else if(UDF.RETURN_FORMAT_SERIALIZE==argumentsCollectionFormat)  {
        str = new ScriptConverter().serialize(args);
        formfields.put("argumentCollectionFormat", "cfml");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.