public static void generateParamSerializer ( BindTypeContext context , String propertyName , TypeName parameterTypeName , PersistType persistType ) { propertyName = SQLiteDaoDefinition . PARAM_SERIALIZER_PREFIX + propertyName ; MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( propertyName ) . addJavadoc ( "for param $L serialization\n" , propertyName ) . addParameter ( ParameterSpec . builder ( parameterTypeName , "value" ) . build ( ) ) ; methodBuilder . addModifiers ( context . modifiers ) ; switch ( persistType ) { case STRING : methodBuilder . returns ( className ( String . class ) ) ; break ; case BYTE : methodBuilder . returns ( TypeUtility . arrayTypeName ( Byte . TYPE ) ) ; break ; } methodBuilder . beginControlFlow ( "if (value==null)" ) ; methodBuilder . addStatement ( "return null" ) ; methodBuilder . endControlFlow ( ) ; methodBuilder . addStatement ( "$T context=$T.jsonBind()" , KriptonJsonContext . class , KriptonBinder . class ) ; methodBuilder . beginControlFlow ( "try ($T stream=new $T(); $T wrapper=context.createSerializer(stream))" , KriptonByteArrayOutputStream . class , KriptonByteArrayOutputStream . class , JacksonWrapperSerializer . class ) ; methodBuilder . addStatement ( "$T jacksonSerializer=wrapper.jacksonGenerator" , JsonGenerator . class ) ; methodBuilder . addStatement ( "int fieldCount=0" ) ; BindTransform bindTransform = BindTransformer . lookup ( parameterTypeName ) ; String serializerName = "jacksonSerializer" ; boolean isInCollection = true ; if ( ! BindTransformer . isBindedObject ( parameterTypeName ) ) { methodBuilder . addStatement ( "$L.writeStartObject()" , serializerName ) ; isInCollection = false ; } BindProperty property = BindProperty . builder ( parameterTypeName ) . inCollection ( isInCollection ) . elementName ( DEFAULT_FIELD_NAME ) . build ( ) ; bindTransform . generateSerializeOnJackson ( context , methodBuilder , serializerName , null , "value" , property ) ; if ( ! BindTransformer . isBindedObject ( parameterTypeName ) ) { methodBuilder . addStatement ( "$L.writeEndObject()" , serializerName ) ; } methodBuilder . addStatement ( "$L.flush()" , serializerName ) ; switch ( persistType ) { case STRING : methodBuilder . addStatement ( "return stream.toString()" ) ; break ; case BYTE : methodBuilder . addStatement ( "return stream.toByteArray()" ) ; break ; } methodBuilder . nextControlFlow ( "catch($T e)" , Exception . class ) ; methodBuilder . addStatement ( "throw(new $T(e.getMessage()))" , KriptonRuntimeException . class ) ; methodBuilder . endControlFlow ( ) ; context . builder . addMethod ( methodBuilder . build ( ) ) ; }
Generate param serializer .