Examples of JSerializerType


Examples of com.github.nmorel.gwtjackson.rebind.type.JSerializerType

                ImmutableList.Builder<JSerializerType> parametersSerializerBuilder = ImmutableList.builder();
                String[] params = new String[typeArgs.length];

                for ( int i = 0; i < params.length; i++ ) {
                    JSerializerType parameterSerializerType;
                    if ( MapperType.KEY_SERIALIZER == configuredSerializer.get().getParameters()[i] ) {
                        parameterSerializerType = getKeySerializerFromType( typeArgs[i] );
                    } else {
                        parameterSerializerType = getJsonSerializerFromType( typeArgs[i], subtype );
                    }
                    parametersSerializerBuilder.add( parameterSerializerType );
                    params[i] = parameterSerializerType.getInstance();
                }
                builder.parameters( parametersSerializerBuilder.build() );
                builder.instance( String.format( configuredSerializer.get().getInstanceCreation(), params ) );

            } else {
                builder.instance( configuredSerializer.get().getInstanceCreation() );
            }
            return builder.build();
        }

        JEnumType enumType = type.isEnum();
        if ( null != enumType ) {
            return builder.instance( String.format( "%s.<%s<%s>>getInstance()", EnumJsonSerializer.class
                    .getCanonicalName(), EnumJsonSerializer.class.getCanonicalName(), enumType.getQualifiedSourceName() ) ).build();
        }

        if ( Enum.class.getName().equals( type.getQualifiedSourceName() ) ) {
            return builder.instance( String.format( "%s.getInstance()", EnumJsonSerializer.class.getCanonicalName() ) ).build();
        }

        JArrayType arrayType = type.isArray();
        if ( null != arrayType ) {
            String arraySerializer;
            if ( arrayType.getRank() == 1 ) {
                // one dimension array
                arraySerializer = ArrayJsonSerializer.class.getCanonicalName();
            } else if ( arrayType.getRank() == 2 ) {
                // two dimension array
                arraySerializer = Array2dJsonSerializer.class.getCanonicalName();
            } else {
                // more dimensions are not supported
                String message = "Arrays with 3 or more dimensions are not supported";
                logger.log( TreeLogger.Type.WARN, message );
                throw new UnsupportedTypeException( message );
            }
            JSerializerType parameterSerializerType = getJsonSerializerFromType( arrayType.getLeafType(), subtype );
            builder.parameters( ImmutableList.of( parameterSerializerType ) );
            return builder.instance( String.format( "%s.newInstance(%s)", arraySerializer, parameterSerializerType.getInstance() ) )
                    .build();
        }

        if ( null != type.isAnnotation() ) {
            String message = "Annotations are not supported";
            logger.log( TreeLogger.Type.WARN, message );
            throw new UnsupportedTypeException( message );
        }

        JClassType classType = type.isClassOrInterface();
        if ( null != classType ) {
            // it's a bean
            JClassType baseClassType = classType;
            JParameterizedType parameterizedType = classType.isParameterized();
            if ( null != parameterizedType ) {
                // it's a bean with generics, we create a serializer based on generic type
                baseClassType = parameterizedType.getBaseType();
            }

            BeanJsonSerializerCreator beanJsonSerializerCreator = new BeanJsonSerializerCreator( logger
                    .branch( Type.DEBUG, "Creating serializer for " + baseClassType
                            .getQualifiedSourceName() ), context, configuration, typeOracle );
            String qualifiedClassName = beanJsonSerializerCreator.create( baseClassType );

            ImmutableList<? extends JType> typeParameters = getTypeParameters( classType, subtype );
            StringBuilder joinedTypeParameterSerializers = new StringBuilder();
            if ( !typeParameters.isEmpty() ) {
                ImmutableList.Builder<JSerializerType> parametersSerializerBuilder = ImmutableList.builder();
                boolean first = true;
                for ( JType argType : typeParameters ) {
                    if ( first ) {
                        first = false;
                    } else {
                        joinedTypeParameterSerializers.append( ", " );
                    }

                    JSerializerType parameterSerializerType = getJsonSerializerFromType( argType, subtype );
                    parametersSerializerBuilder.add( parameterSerializerType );
                    joinedTypeParameterSerializers.append( parameterSerializerType.getInstance() );
                }
                builder.parameters( parametersSerializerBuilder.build() );
            }

            builder.beanMapper( true );
View Full Code Here

Examples of com.github.nmorel.gwtjackson.rebind.type.JSerializerType

        if ( !properties.isEmpty() ) {
            Map<PropertyInfo, JSerializerType> propertiesMap = new LinkedHashMap<PropertyInfo, JSerializerType>();
            for ( PropertyInfo propertyInfo : properties.values() ) {
                if ( null != propertyInfo && propertyInfo.getGetterAccessor().isPresent() && !propertyInfo.isIgnored() ) {
                    if ( propertyInfo.isRawValue() ) {
                        JSerializerType serializerType = new JSerializerType.Builder().type( propertyInfo.getType() ).instance( String
                                .format( "%s.<%s>getInstance()", RawValueJsonSerializer.class.getCanonicalName(), propertyInfo.getType()
                                        .getParameterizedQualifiedSourceName() ) ).build();
                        propertiesMap.put( propertyInfo, serializerType );
                    } else {
                        try {
                            JSerializerType serializerType = getJsonSerializerFromType( propertyInfo.getType() );
                            propertiesMap.put( propertyInfo, serializerType );
                        } catch ( UnsupportedTypeException e ) {
                            logger.log( Type.WARN, "Property '" + propertyInfo.getPropertyName() + "' is ignored." );
                        }
                    }
View Full Code Here

Examples of com.github.nmorel.gwtjackson.rebind.type.JSerializerType

        source.println( "%s map = new %s%s(%s);", resultType, IdentityHashMap.class.getCanonicalName(), mapTypes, subtypes.size() );
        source.println();

        for ( JClassType subtype : subtypes ) {

            JSerializerType serializerType;
            try {
                serializerType = getJsonSerializerFromType( subtype, true );
            } catch ( UnsupportedTypeException e ) {
                logger.log( Type.WARN, "Subtype '" + subtype.getQualifiedSourceName() + "' is not supported. We ignore it." );
                continue;
            }

            String subtypeClass;
            String serializerClass;
            String subtypeQualifiedClassName;
            if ( configuration.getSerializer( subtype ).isPresent() || null != subtype.isEnum() ) {
                subtypeClass = DefaultSubtypeSerializer.class.getCanonicalName();
                subtypeQualifiedClassName = getQualifiedClassName( subtype );
                serializerClass = String.format( "%s<%s>", JsonSerializer.class.getName(), subtypeQualifiedClassName );
            } else {
                subtypeClass = BeanSubtypeSerializer.class.getCanonicalName();
                serializerClass = String.format( "%s<?>", ABSTRACT_BEAN_JSON_SERIALIZER_CLASS );
            }

            source.println( "map.put( %s.class, new %s() {", subtype.getQualifiedSourceName(), subtypeClass );
            source.indent();

            source.println( "@Override" );
            source.println( "protected %s newSerializer() {", serializerClass );
            source.indent();
            source.println( "return %s;", serializerType.getInstance() );
            source.outdent();
            source.println( "}" );

            source.outdent();
            source.println( "});" );
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.